Thanks in advance for any help you can give me.
I am trying to create a VB application that will open an existing Word document, make some changes and save it with a new file name. Making changes to a document is easy. Saving a document seems to be just as easy, but there is one serious problem. When I try to save the document, a save dialog will open. It needs to be automated, so it won’t work. I tried a bunch of options:
Sub Main()
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim fileName As String
Dim templateName As String
Dim newFileName As String
'Start Word and open the document template.
oWord = CreateObject("Word.Application")
oWord.Visible = False
oWord.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
templateName = "C:\tmp\template.dotx"
fileName = "C:\tmp\document.docx"
newFileName = "C:\tmp\new document.docx"
oDoc = oWord.Documents.Add(templateName)
'oDoc = oWord.Documents.Open(fileName) I have tried both using a template and opening a docx file.
<make changes>
oDoc.SaveAs2(newFileName)
oWord.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
oWord.Application.Quit()
oWord = Nothing
End Sub
He always stops here:
oDoc.SaveAs2
. . , , / , Word. , , , . , .
, - . VB. , , - , , .
,