dean.rogers
New Member
- Joined
- Apr 6, 2012
- Messages
- 31
Hey all,
I am using excel 07 vba to create a word doc. Currently when in my code I have it save as right away to make sure not to affect my template. What I need to do is add a count integer to the save as so if the file exists, it will save like this: fileexists (1).docx
This works great, but i know in order to add a count integer i need to make a statement at the beginning and then add an IF statement that will save it as it is currently if the file doesn't already exist and IF it does exist then Save As with the integer...
Thanks for your help!!
I am using excel 07 vba to create a word doc. Currently when in my code I have it save as right away to make sure not to affect my template. What I need to do is add a count integer to the save as so if the file exists, it will save like this: fileexists (1).docx
Code:
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:\Templates\MyTemplate.docx"
'this saves the file as the value in cell D3
wrdApp.ActiveDocument.SaveAs "C:\Templates\ " & ActiveWorkbook.Sheets("Sheet1").Range("D3").value & " .docx"
This works great, but i know in order to add a count integer i need to make a statement at the beginning and then add an IF statement that will save it as it is currently if the file doesn't already exist and IF it does exist then Save As with the integer...
Thanks for your help!!