Victor
08-25-2015, 07:32 AM
Hi all
I have tis Word 2010 macro which add a sequential name to an invoice number, write it to the file and then store the file with the name of the invoice number.
It works fine but now I want to add a predefine name which I add manually to the file and want it to be part of the file name. I modified the VBA macro enclosed without success.
This is what it does
When run the AutoNEW macro it writes de invoice number 001 and and saves the file as Factura001. When it runs again it adds a number to the previous invoice. In tis case Factura002 and save the file with the name Factura002.
The help I need is how to modify the VBA that if I assign he bookmark name to let say "OB" the file name when saved assign the name "FacturaOB00". Continue Add a number to the invoice number. My problem is with the PreOrder bookmark name and the invoice number is not increasing.
The catch is that is not always OB, so this can not be fixed as part od the macro. That's why I assigned bookmark name.
Enclosed is the VBA Word 2010 AutoNew macro.
Sub AutoNew()
'
' AutoNew Macro
'
'
Order = System.PrivateProfileString("c:\settings.txt", "MacroSettings", "Order")
PreOrder = System.PrivateProfileString("c:\settings.txt", "MacroSettings", "PreOrder")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
On Error Resume Next
System.PrivateProfileString("c:\settings.txt", "MacroSettings", "Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")
ActiveDocument.SaveAs2 FileName:="FACTURA" & Format(PreOrder, "@@") & Format(Order, "00#")
End Sub
Thanks for the help,
I have tis Word 2010 macro which add a sequential name to an invoice number, write it to the file and then store the file with the name of the invoice number.
It works fine but now I want to add a predefine name which I add manually to the file and want it to be part of the file name. I modified the VBA macro enclosed without success.
This is what it does
When run the AutoNEW macro it writes de invoice number 001 and and saves the file as Factura001. When it runs again it adds a number to the previous invoice. In tis case Factura002 and save the file with the name Factura002.
The help I need is how to modify the VBA that if I assign he bookmark name to let say "OB" the file name when saved assign the name "FacturaOB00". Continue Add a number to the invoice number. My problem is with the PreOrder bookmark name and the invoice number is not increasing.
The catch is that is not always OB, so this can not be fixed as part od the macro. That's why I assigned bookmark name.
Enclosed is the VBA Word 2010 AutoNew macro.
Sub AutoNew()
'
' AutoNew Macro
'
'
Order = System.PrivateProfileString("c:\settings.txt", "MacroSettings", "Order")
PreOrder = System.PrivateProfileString("c:\settings.txt", "MacroSettings", "PreOrder")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
On Error Resume Next
System.PrivateProfileString("c:\settings.txt", "MacroSettings", "Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")
ActiveDocument.SaveAs2 FileName:="FACTURA" & Format(PreOrder, "@@") & Format(Order, "00#")
End Sub
Thanks for the help,