Thank you all for your assistance. I am still having problems though. I
have taken your many suggestions and here is what I have. I commented out
the filesaveas to try and isolate the issue. I've checked to make sure an
instance of word is open by the time the code gets to msoFileDialogSaveAs
but
I am still getting the same error. It can't find the library. Everything
runs fine up to that point.
Const Error_NotRunning = 429
Dim newInstance As Boolean
Dim strDocName As String
Dim FullDocPath As Variant
Dim DocPath As Variant
Dim strNewPath As Variant
Dim FromDoc As Document
Dim ToDoc As Document
Dim DebugYes As Boolean
DebugYes = True
On Error Resume Next
If Err.Number = Error_NotRunning Then
MsgBox "An instance of Word is not open."
newInstance = True
Else
MsgBox "An open instance of Word is being used."
newInstance = False
End If
On Error GoTo 0
If newInstance = True Then
Exit Sub
End If
'set this document as "ToDoc"
Set ToDoc = ActiveDocument
If DebugYes = True Then
Debug.Print "ToDoc ", ToDoc.Name
End If
With Dialogs(wdDialogFileOpen)
If .show = -1 Then
strDocName = .Name
FullDocPath = WordBasic.FilenameInfo(.Name, 1)
DocPath = WordBasic.FilenameInfo(.Name, 5)
Else
MsgBox "No file selected"
Exit Sub
End If
End With
strNewPath = DocPath & "New " & strDocName
'set newly opened doc as "FromDoc"
Set FromDoc = ActiveDocument (I tried brackets here but the editor
would not accept them - Set FromDoc = Documents.Open[FullDocPath]. I get
an
expected end of statement error.)
If DebugYes = True Then
Debug.Print "FullDocPath ", FullDocPath
Debug.Print "DocPath ", DocPath
Debug.Print "strDocName ", strDocName
Debug.Print "FromDoc ", FromDoc.Name
Debug.Print "ToDoc ", ToDoc.Name
Debug.Print "strNewPath ", strNewPath
End If
*
*
*
FromDoc.Close
If DebugYes = True Then
On Error Resume Next
If Err.Number = Error_NotRunning Then
Debug.Print "An instance of Word is not open."
Else
Debug.Print "An open instance of Word is being used."
End If
On Error GoTo 0
End If
' With Dialogs(msoFileDialogSaveAs)
'.InitialFileName = strNewPath
'.Title = "Save As"
'.Show
'.Execute (I tried it without this when I removed the comments. I
am not sure I need this?)
'End With
End Sub
--
Thanks for your help.
Eileen
Doug Robbins - Word MVP said:
Replace .Display with .Show so that the selected document is opened and
then
set FromDoc as the ActiveDocument
With Dialogs(wdDialogFileOpen)
If .Show = -1 Then
strDocName = .Name
DocPath = WordBasic.FilenameInfo(.Name, 5)
Else
MsgBox "No file selected"
Exit Sub
End If
End With
'set newly opened doc as "FromDoc"
Set FromDoc = ActiveDocument
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Sorry, I forgot it was an object, and therefore needs the brackets.
Set FromDoc = Documents.Open(strDocName)
Fumei2 wrote:
If you are running this from Word, then you do not need an extra
instance
of
Word. You can use the current one.
Set FromDoc = appWord.Documents.Open(strDocName)
In your code, strDocName has no value.
Set FromDoc = Documents.Open Filename:= strDocName
should work if strDocName has a valid path and filename.
One more question if you don't mind. What about my fileopen open
code.
This
is all from Word. I don't need the object at all then, correct? I
had
[quoted text clipped - 5 lines]
.Execute
End With