Jack Feeman
12-07-2007, 11:29 AM
I have Document_New() code that auto-names a document based on an external text file.
The VBA runs when the template is opened by the using from a website (SharePoint) and assigns a filename of {000-07} and places it in the document at a predefine location (bookmarked as Order). It works great on my machine only and errors on everyone else's. I assume that it is because it is trying to write to each person;s registry even though nothing in the VBA (except possibly PrivateProfileString). Is there anything that can be done to prevent the code from trying to write to the registry? Is there another expression that can be used that doesn't send it to the registry. My current code follows. The part about saving back to the web server using the document name as the filename has been commented out until I can get that to work (actually it works just doesn't append filename with the .doc file extension).
///Code follows:///
Private Sub Document_New()
' Unprotect document to run macro
ActiveDocument.Unprotect
Order = System.PrivateProfileString("\\{server}/{dir}/{sub-dir}/ECN.txt (file://\\{server}/{dir}/{sub-dir}/ECN.txt)", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("\\{server}/{dir}/{sub-dir}/ECN.txt (file://%7Bserver%7D/%7Bdir%7D/%7Bsub-dir%7D/ECN.txt)", "MacroSettings", _
"Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore _
Format(Order, "00#") & "-" & Format(Now, "YY")
'ActiveDocument.SaveAs FileName:=Format(Order, "00#") & "-" & Format(Now, "YY")
' Re-protect document for Forms after running macro
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
' Save ECN with ECN number for file name and in the ECN library
'ActiveDocument.SaveAs FileName:=http://{webserver}/{site}/{sub-site} & _
'Format(Order, "00#") & "-" & Format(Now, "YY")
End Sub
///End Code///
Thanks
Jack
The VBA runs when the template is opened by the using from a website (SharePoint) and assigns a filename of {000-07} and places it in the document at a predefine location (bookmarked as Order). It works great on my machine only and errors on everyone else's. I assume that it is because it is trying to write to each person;s registry even though nothing in the VBA (except possibly PrivateProfileString). Is there anything that can be done to prevent the code from trying to write to the registry? Is there another expression that can be used that doesn't send it to the registry. My current code follows. The part about saving back to the web server using the document name as the filename has been commented out until I can get that to work (actually it works just doesn't append filename with the .doc file extension).
///Code follows:///
Private Sub Document_New()
' Unprotect document to run macro
ActiveDocument.Unprotect
Order = System.PrivateProfileString("\\{server}/{dir}/{sub-dir}/ECN.txt (file://\\{server}/{dir}/{sub-dir}/ECN.txt)", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("\\{server}/{dir}/{sub-dir}/ECN.txt (file://%7Bserver%7D/%7Bdir%7D/%7Bsub-dir%7D/ECN.txt)", "MacroSettings", _
"Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore _
Format(Order, "00#") & "-" & Format(Now, "YY")
'ActiveDocument.SaveAs FileName:=Format(Order, "00#") & "-" & Format(Now, "YY")
' Re-protect document for Forms after running macro
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
' Save ECN with ECN number for file name and in the ECN library
'ActiveDocument.SaveAs FileName:=http://{webserver}/{site}/{sub-site} & _
'Format(Order, "00#") & "-" & Format(Now, "YY")
End Sub
///End Code///
Thanks
Jack