Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jack_Feeman - 19 Nov 2007 14:30 GMT
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örg - 19 Nov 2007 14:59 GMT
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...
Jack_Feeman - 19 Nov 2007 15:11 GMT
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

> 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...
Russ - 19 Nov 2007 19:05 GMT
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'.

> Word 2003
> I have accomplished most of what I needed to do already but one more issue.
[quoted text clipped - 47 lines]
> Thanks
> Jack

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Jack_Feeman - 20 Nov 2007 12:45 GMT
Thanks Russ,
I will look  up the storing reference you mentioned. Hopefully there is a
work-a-round somewhere.
Jack

> Jack,
> PrivateProfileString writes to the local Windows OS registry. Could it be
[quoted text clipped - 56 lines]
> > Thanks
> > Jack
Russ - 20 Nov 2007 22:30 GMT
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
[quoted text clipped - 56 lines]
>> Thanks
>> Jack

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Jack_Feeman - 21 Nov 2007 14:43 GMT
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

> Jack,
> I realize now that you weren't using PrivateProfileString to write to the
[quoted text clipped - 92 lines]
> >> Thanks
> >> Jack
Jack_Feeman - 02 Jan 2008 15:03 GMT
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

> Word 2003
> I have accomplished most of what I needed to do already but one more issue.
[quoted text clipped - 47 lines]
> Thanks
> Jack
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.