+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    06-03-2009
    Location
    Mountain View, CA
    MS-Off Ver
    Excel 2003
    Posts
    46

    Discrepancy between Word and Excel syntax?

    Edit: Cross-posted at http://www.mrexcel.com/forum/showthread.php?t=422923

    Hi All,

    I should disclaim that I'm quite novice at that, so my approach to writing macros is to record individual steps to determine the appropriate method, then copy and paste.

    In any event, I have a macro that creates a word doc from content in an excel file. I copied over the code for inserting a text field from the Word Macro Recorder:

    Code:
        Selection.FormFields.Add Range:=Selection.Range, Type:= _
            wdFieldFormTextInput
    And pasted it (with msWord):

    Code:
        With msWord
            .Selection.TypeParagraph
            .Selection.InsertDateTime DateTimeFormat:="M/d/yyyy", InsertAsField:=False, _
                DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
                InsertAsFullWidth:=False
            .Selection.TypeParagraph
            .Selection.TypeParagraph
            .Selection.TypeText Text:="Dear "
            .Selection.FormFields.Add Range:=Selection.Range, Type:= _     wdFieldFormTextInput
            .Selection.TypeParagraph
    End With
    When I attempt to run this I get a "wrong number of arguments or invalid property assignment" error at the line that attempts to add the text field. Is this because of a discrepancy in syntax between Word and Excel, or am I making some other mistake?

    Any help you can provide would be great. Thanks!
    Last edited by prawer; 10-15-2009 at 09:53 PM. Reason: Cross-posted

  2. #2
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2007
    Posts
    9,508

    Re: Discrepancy between Word and Excel syntax?

    Thanks for including the link.......
    Last edited by daddylonglegs; 10-15-2009 at 08:52 PM.

  3. #3
    Registered User
    Join Date
    06-03-2009
    Location
    Mountain View, CA
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Discrepancy between Word and Excel syntax?

    My apologies all. Have added the link and will 'cross-close' if my issue gets resolved in either forum.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,497

    Re: Discrepancy between Word and Excel syntax?

    Hello prawer,

    It would be best if you posted your workbook so the all the code is available for review..
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    06-03-2009
    Location
    Mountain View, CA
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Discrepancy between Word and Excel syntax?

    The good folks at mrexcel (who are, of course, no more or less good than the good folks here ) pointed out that the second 'Selection' in the line needed a preceding period in order to go with 'with', as follows:

    Code:
    .Selection.FormFields.Add Range:=.Selection.Range, Type:=wdFieldFormTextInput
    Cheers y'all.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0