Auto_new VBA to autoname a document and autosave to a specific pat

J

Jack_Feeman

Word 2003
I have accomplished most of what I needed to do already but one more issue.
I have a Word document that is stored on a SharePoint site as a template (but
still a .doc) file. An auto_new sub is started to bookmark a place in the
document and auto-name the document based on an external text document that
tracks the last used filename and renames the document sequentially and saves
it back to the SharePoint site as that sequential filename. It was absolutely
great on my machine when the external file is stored/access on a network
share. I tried storing the external file in the same directory on the site
but that doesn't work. When others try it on their computers (Word 2003), the
document opens but they get an error msg that says: Run-Time Error
'-2147467259(80004005)': Method 'PrivateProfileString' of object 'System'
failed
My code is:
Private Sub Document_New()
' Unprotect document to run macro
ActiveDocument.Unprotect

Order = System.PrivateProfileString("\\Northstar\headquarters\Departmental
Folders\TWG\ECN.txt", _
"MacroSettings", "Order")
'Order = System.PrivateProfileString("http://docrep/vmc/ecn/ECN.txt", _
'"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString("\\server\share\dir\subdir\ECN.txt",
"MacroSettings", _
"Order") = Order

'System.PrivateProfileString("http://servername/site/subsite/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://docrep/vmc/ecn/ChangeRequests/" & _
Format(Order, "00#") & "-" & Format(Now, "YY")

End Sub
Any ideas why is errors on all others machine but not on mine.
Thanks
Jack
 
J

Jörg

Could it be, that your users don't have write access to the http path? You
increment the value... I would open the file on one of the clients and check.
Things are not allways what they seem...
 
J

Jack_Feeman

Hi Jörg,
Thanks for the fast reply. I thought that it might be permissions but even
other administrators with full control get the error. The document does open
but the auto naming/autosaving is not performed. All our Office security
settings are on Medium. Since it didn't even autoname the document and place
the name in the header (which is before saving in the code), it threw me for
a loss. I am a beginner at VBA so I was thinking it had to do with using
private (profile) strings in a public manner or something.
Thanks again
Jack
 
R

Russ

Jack,
PrivateProfileString writes to the local Windows OS registry. Could it be
that the other people don't have sufficient privileges to change their
Windows Registry? Or your macro, since it is owned by you, can't change
their Registry?

Also to see other methods to store information after a macro ends, go to VBA
help and search on the word 'storing'.
 
J

Jack_Feeman

Thanks Russ,
I will look up the storing reference you mentioned. Hopefully there is a
work-a-round somewhere.
Jack
 
R

Russ

Jack,
I realize now that you weren't using PrivateProfileString to write to the
Window's Registry. You were using a file, not a registry key.

I am not familiar with using SharePoint or a document server.

You say that it errors when coming across the first PrivateProfileString
line in the code, which appears to be a read file attempt? Can others use
PrivateProfileString to write and read their own files from their end?

Googling the error numbers you posted yields information mostly concerning
databases and connecting to them. For example:
========Quote
Connectivity Problems for Error 80004005

Firstly, the error 80004005 may be 'by design' in that the database has been
locked by another process or user and therefore cannot accept a connection
at this time.

Causes of Connectivity related Problems

As with all 80004005, I would start with permissions. You may get a good
clue such as 'Login Failed' or [ODBC Microsoft SQL Driver] Logon Failed().

When a database is on a different server from the Web server. Sometimes the
problem is using a UNC path to reference a database. One nasty problem
with UNC paths is that even if the database is on the same computer as the
Web server, the Web server assumes that the database resides on a different
computer.
==========UnQuote

This is related to ASP and non-database error issues:
http://www.aspfaq.com/show.asp?id=2413

If you come across the solution, please share it with the forum.
 
J

Jack_Feeman

Thanks Russ, I will.
I have our VBA programmer looking at it also.
It runs fine from my computer but the error is received when someone opens
the same document from the same web server on their machines. So it is
natural to think it has something to do with permissions. registry or IE
settings.
Thanks
Jack

Russ said:
Jack,
I realize now that you weren't using PrivateProfileString to write to the
Window's Registry. You were using a file, not a registry key.

I am not familiar with using SharePoint or a document server.

You say that it errors when coming across the first PrivateProfileString
line in the code, which appears to be a read file attempt? Can others use
PrivateProfileString to write and read their own files from their end?

Googling the error numbers you posted yields information mostly concerning
databases and connecting to them. For example:
========Quote
Connectivity Problems for Error 80004005

Firstly, the error 80004005 may be 'by design' in that the database has been
locked by another process or user and therefore cannot accept a connection
at this time.

Causes of Connectivity related Problems

As with all 80004005, I would start with permissions. You may get a good
clue such as 'Login Failed' or [ODBC Microsoft SQL Driver] Logon Failed().

When a database is on a different server from the Web server. Sometimes the
problem is using a UNC path to reference a database. One nasty problem
with UNC paths is that even if the database is on the same computer as the
Web server, the Web server assumes that the database resides on a different
computer.
==========UnQuote

This is related to ASP and non-database error issues:
http://www.aspfaq.com/show.asp?id=2413

If you come across the solution, please share it with the forum.
Jack,
PrivateProfileString writes to the local Windows OS registry. Could it be
that the other people don't have sufficient privileges to change their
Windows Registry? Or your macro, since it is owned by you, can't change
their Registry?

Also to see other methods to store information after a macro ends, go to VBA
help and search on the word 'storing'.
 
J

Jack_Feeman

Can •Anyone• suggest a method different than 'PrivateProfileString' for this
VBA? Read the error I get below. It is the only thing I need to reolve to get
this working.
Thanks and Hope you all had a great holiday!
Jack
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top