Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with macro to close word doc

Status
Not open for further replies.

ReportSmithing

Programmer
Apr 15, 2005
41
US
I'm working on an application that uses VB5. I'm using the shell() command in which I open a word document from our shared drive (R:) and then poke data into the doc and then save this to C:\My Documents.

Here's the problem, if another user attempts to the run the same application, an error will occur saying that the document is locked by a user. I had thought that if it opened the doc from the R: drive and saved the doc to the C: drive that the R: drive doc shouldn't be active since it's now in C: - I find it's active on both drives!

What code could I add to the below macro to deactivate the document on the R: drive and keep the saved doc on the C: drive up and running?

Sub SaveMeToTemp()
'
' SaveMeToDrive Macro
' Macro created 6/1/2005 by hmrl9cc
'
Dim strFileA, strFileB
strFileA = ActiveDocument.Name
strFileB = "C:\My Documents\" & Format(Date, "yyyy-mm-dd") & "_" & Format(Time, "hh-mm-ss") & "_" & strFileA
ActiveDocument.SaveAs FileName:=strFileB
End Sub

Here my code
 
Instead of open the R:xxx.doc create a new one using it as template:
Set yourDocObjet = yourWordObject.Documents.Add("R:\path\to\file.doc")
...
yourDocObjet.SaveAs FileName:=strFileB

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top