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:
And pasted it (with msWord):Code:Selection.FormFields.Add Range:=Selection.Range, Type:= _ wdFieldFormTextInput
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?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
Any help you can provide would be great. Thanks!
Last edited by prawer; 10-15-2009 at 09:53 PM. Reason: Cross-posted
Thanks for including the link.......
Last edited by daddylonglegs; 10-15-2009 at 08:52 PM.
My apologies all. Have added the link and will 'cross-close' if my issue gets resolved in either forum.
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
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:
Cheers y'all.Code:.Selection.FormFields.Add Range:=.Selection.Range, Type:=wdFieldFormTextInput
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks