I am using the code below to insert a number from a .txt file, "save-as" the word file using that number as the name, then completing a mail merge.
The code worked fine until I had to switch computers, so file locations changed...I obviously changed the locations to match those of the new computer.
Now, the number is inserted in the correct place, then the save dialog box opens but it doesn't put it in the right location nor does it insert the specified number.
It tries to save it here no matter what I change the file path to be: C:\Users\Schlechter Ag Liquid\OneDrive\BOLTemplate\
Sub CommandButton1_Click()
Invoice = System.PrivateProfileString("C:\Users\Schlechter Ag Liquid\OneDrive\BOLTemplate\" & _
"invoice-number.txt", "InvoiceNumber", "Invoice")
If Invoice = "" Then
Invoice = 1
Else
Invoice = Invoice + 1
End If
System.PrivateProfileString("C:\Users\Schlechter Ag Liquid\OneDrive\BOLTemplate\" & _
"invoice-number.txt", "InvoiceNumber", "Invoice") = Invoice
' Insert the number in the document
ActiveDocument.Bookmarks("Invoicenan").Range.InsertBefore Format(Invoice, "")
ActiveDocument.SaveAs FileName:= _
"C:\Users\Schlechter Ag Liquid\OneDrive\BOLs\" & Format(Invoice, "") & ".docx"
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Users\Schlechter Ag Liquid\OneDrive\BOLTemplate\Customer Database.accdb" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Users\Schlechter Ag Liquid\OneDrive\BOLTemplate\Customer Database.accdb;Mode=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=6;Jet OLE" _
, SQLStatement:="SELECT * FROM `report1 (1)`", SQLStatement1:="", SubType _
:=wdMergeSubTypeAccess
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
WordBasic.MailMergeFindEntry
End Sub
It says that the error is in this line, but I can't seem to figure out what is wrong with it.
ActiveDocument.SaveAs FileName:= _
"C:\Users\Schlechter Ag Liquid\OneDrive\BOLs\" & Format(Invoice, "") & ".docx"
Any help would be greatly appreciated.