Thanks for the references
Thank you for addressing my problem. I appreciate your time.
It seems strange to me that the "macro recorder" would create code that would not work from outside its environment. Perhaps my problem was not knowing this fact in the first place.
I originally addressed this problem using "bookmarks", but I was unable to figure out how to get rid of the bookmarks or the command to "change" the bookmark to text. From what I read in the MS documents, you can set a range and then replace text.
Ideally, the range sounds like a good way to address this problem. I would insert the property name and date, and then the dollar amounts. None of these items are always the same length, so a true byte offset is altered by the insertion of the text (for all but the first inserted text). I am hoping the Range somehow accomodates this fact.
Thanks again for your help.
Word template attachment for above
To test the previously included macro, please use this template.
I had to alter the document for file size considerations. I hope this still works. I had problems trying to zip the files, so I couldn't do that to beat the rules. Sorry... I also had to rename it. You will need to change the name back to ".dot" instead of ".doc"
TIA
Print works! How do I save Word document?
Thanks to Charlize. The Wait fixed that problem.
After I used the routine, the boss asked if I could save the Word document so that it could be emailed later. The net of this is that the "print" statement now needs to be a "save".
Code:
ChangeFileOpenDirectory (docPath)
ActiveDocument.SaveAs FileName:=docName, FileFormat:= wdFormatDocument, LockComments:=False, _
Password:="", AddToRecentFiles:= True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
' wrdApp.ChangeFileOpenDirectory (docPath)
' wrdApp.ActiveDocument.SaveAs FileName:=docName, FileFormat:= _
' wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:= False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
The "ChangeFileOpenDirectory" and "docName" variable were traced with the debugger and have the appropriate variables. I turned on Word visibility and I can switch to Word BEFORE the save attempt and see that everything is properly set up.
The commented-out code was a previous attempt to solve this problem.
Here is the original code (and it works thanks to Charlize and others!) that I wanted to replace:
Code:
wrdApp.Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= wdPrintDocumentContent, Copies:=1, Pages:="", _
PageType:=wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
The error comes immediately in the debugger, so I'm sure that the "object" is checking my request and finding some error.
Any ideas?