File Path Name

L

Lee

I am wanting to find out the code for file name. I have
documents that need a copy automatically saved to a
different location on close (for intranet purposes) but am
unsure how to save the doc as it's original name (where
the ???? are below). The coding I have so far is:

Private Sub Document_Close()

Dim Save2Intranet As Boolean
Save2Intranet = MsgBox("You are about to close. Do you
wish to save a copy to the intranet?", vbYesNo) = vbYes
If Save2Intranet Then
Me.SaveAs "\\ruth\inetpub\wwwroot\apps\news\newsreleases\"
& ????, wdFormatFilteredHTML
End If
End Sub

Thanks
 
J

Jezebel

If the document has been saved already, you can use ActiveDocument.Name. If
it's never been saved this returns 'Document1' (or whatever number you're up
to).

Your code uses the 'me' keyword -- this doesn't work in VBA as a reference
to the ActiveDocument.
 
P

Peter Hewett

Hi Lee

As long as it's always the ActiveDcoument you're saving you could replace
???? with "ActiveDocument.Name". If it's not always the ActiveDcoument you're
saving you should pass the name of the file to the procedure, something like:

Public Sub SaveToIntranet(ByVal strFilename As String)
Dim Save2Intranet As Boolean

Save2Intranet = MsgBox("You are about to close. " & _
"Do you wish to save a copy to the intranet?", vbYesNo) = vbYes
If Save2Intranet Then
Me.SaveAs "\\ruth\inetpub\wwwroot\apps\news\newsreleases\" & _
strFilename, wdFormatFilteredHTML
End If
End Sub

You'd call the procedure using something like:

Dim docImUsing As Word.Document

SaveToIntranet docImUsing.Name

HTH + Cheers - Peter
 
L

Lee

Hi

I have worked it out... file name coding =
ActiveDocument.Name BUT it will not save it as filtered
HTML (wdFormatFilteredHTML)....

So the coding I have is:

Private Sub Document_Close()

Dim Save2Intranet As Boolean
Save2Intranet = MsgBox("You are about to close. Do you
wish to save a copy to the intranet?", vbYesNo) = vbYes
If Save2Intranet Then
Me.SaveAs "\\ruth\inetpub\wwwroot\apps\news\newsreleases\"
& ActiveDocument.Name, wdFormatFilteredHTML
End If
End Sub
 
P

Peter Hewett

Hi Lee

Please ignore that last post I'm having a bad-brain day! Here's what you
need to do:

Public Sub SaveToIntranet(ByVal docToSave As Word.Document)
Dim Save2Intranet As Boolean

Save2Intranet = MsgBox("You are about to close. " & _
"Do you wish to save a copy to the intranet?", vbYesNo) = vbYes
If Save2Intranet Then
docToSave.SaveAs "\\ruth\inetpub\wwwroot\apps\news\newsreleases\" & _
strFilename, wdFormatFilteredHTML
End If
End Sub

Always call the above procedure using either:

SavetoIntranet ActiveDocument

or if it's another document you want to save, that you've already got a
document object reference for, use something like:

Dim docImUsing As Word.Document

SaveToIntranet docImUsing.Name

Sorry about that + Cheers - Peter
 
P

Peter Hewett

Hi Lee

That'll teach me to try out the code before posting try this:

Public Sub SaveToIntranet(ByVal docToSave As Word.Document)
Dim Save2Intranet As Boolean

Save2Intranet = MsgBox("You are about to close. " & _
"Do you wish to save a copy to the intranet?", vbYesNo) = vbYes
If Save2Intranet Then
docToSave.SaveAs ""\\ruth\inetpub\wwwroot\apps\news\newsreleases\" & _
docToSave.Name, wdFormatHTML
End If
End Sub

Sorry about all this - It REALLY is bad-brain day!
 
C

Charles Kenyon

One other concern is that your code does not save to the hard drive first.
You may end up with different variations on your intranet than on the
originator's hard drive.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
L

Lee

I have written other code that runs when the user fills in
a user form and this code saves the original to another
place (e.g. on a network) so the document is already
saved. We do not have harddrives as we use dumb terminals
due to being on a network....
 

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