PDA

View Full Version : [SOLVED:] Save As?



gibbo1715
02-20-2005, 04:09 AM
I have the code below to use excel to open a word document, what i need to figure out is how to do a save as instead of resaving the original document

Any Help Much appreciated

Gibbo


Option Explicit

Sub openWordPlease()
' dont forget to set a ref to word object library
Dim wordApp As Object
Dim wordFile As Object
Dim myFile As String
Dim Rename As String
myFile = ThisWorkbook.Path & "\Test.doc"
Rename = "Test" & Now() & ". Doc"
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True
Set wordFile = wordApp.Documents.Open(myFile)
On Error GoTo 0
If wordFile Is Nothing Then
MsgBox "File is not found!", vbInformation, "ERROR"
GoTo quickEnd
End If
With wordFile
.Range.Text = Range("A1").Value
.SaveAs ThisWorkbook.Path & Rename
End With
'wordApp.Quit
quickEnd:
Set wordFile = Nothing
Set wordApp = Nothing
End Sub


:banghead:

Norie
02-20-2005, 11:45 AM
What problem do you actually have?

That code looks OK to me.

gibbo1715
02-20-2005, 11:51 AM
Thanks for your interest Norie

The problem was to do with the date format not being compatible (the / part)


Rename = "Test" & Now() & ". Doc"
This thread wasnt working earlier so i posted another one

http://www.vbaexpress.com/forum/showthread.php?t=1953

This is solved there and i ve posted the working code if you wanna have a look

Cheers

Gibbo