Trouble with FileDialog(msoFileDialogSaveAs)

E

Eileen

Hi,

I hope someone can help me. I close a document with the code below. It
worked fine on my desktop. It worked fine on other desktops but not all.
They would get the error message "Compile error ... can't find project or
library" at msoFileDialogSaveAs and I am unable to figure out why.

I began experimenting with the document on my desktop and now it won't run
on mine either and I don't know what I did to change it.

Does anyone have any suggestions as to what I've missed?


With Application.FileDialog(msoFileDialogSaveAs)
.InitialFileName = "New" & strDocName
.Title = "Save As"
.Show
.Execute
End With
 
E

Eileen

Hi,

I tried this as well with the same result. I am using Word 2003.

With Application.FileDialog(msoFileDialogSaveAs)
'check if action button is pressed
If .Show = -1 Then
Select Case .DialogType
Case msoFileDialogSaveAs:
.InitialFileName = "New " & strDocName
.Title = "Save As"
.Execute
Case Else
'Do nothing otherwise.
End Select
Else
' If Cancel pressed do nothing
End If

End With
 
E

Eileen

Hi,

And I've tried this. I get a compile error at msoFileDialogSaveAs saying
it can't find the project or library. Is there something else I need to do
so it can access the library?

With Application.FileDialog(msoFileDialogSaveAs)
'If the user presses the action button...
If .Show = -1 Then
.InitialFileName = "New " & strDocName
.Title = "Save As"
.Execute
Else
'do nothihg
End If

End With
 
D

Doug Robbins - Word MVP

From where is your code getting strDocName?

--
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
 
E

Eileen

Hi Doug,

I obtain it earlier in the procedure.

Dim appWord As Object
Dim strDocName As String
Dim DocPath As Variant
Dim FromDoc As Document
Dim ToDoc As Document
Dim DebugYes As Boolean

DebugYes = True

Set appWord = GetObject(, "Word.Application")
'set this document as "ToDoc"
Set ToDoc = ActiveDocument

If DebugYes = True Then
Debug.Print "ToDoc ", ToDoc.Name
End If

With Dialogs(wdDialogFileOpen)
If .Display = -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 = appWord.Documents.Open(strDocName)

--
Thanks for your help.
Eileen


Doug Robbins - Word MVP said:
From where is your code getting strDocName?

--
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
 
D

Doug Robbins - Word MVP

From what application are you running the code? Do you have the appropriate
references to the necessary object models?

If Word is not running, the GetObject command will fail so you need to trap
that error and use CreateObject when it occurs.

--
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

Eileen said:
Hi Doug,

I obtain it earlier in the procedure.

Dim appWord As Object
Dim strDocName As String
Dim DocPath As Variant
Dim FromDoc As Document
Dim ToDoc As Document
Dim DebugYes As Boolean

DebugYes = True

Set appWord = GetObject(, "Word.Application")
'set this document as "ToDoc"
Set ToDoc = ActiveDocument

If DebugYes = True Then
Debug.Print "ToDoc ", ToDoc.Name
End If

With Dialogs(wdDialogFileOpen)
If .Display = -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 = appWord.Documents.Open(strDocName)
 
P

Pesach Shelnitz

Hi Eileen,

I'd like to add some details to Doug's last response. The call to GetObject
should be used only in code that is invoked in an application other than
Word. If you are running the code from Word, delete the line containing
GetObject and remove appWord everywhere in your code.

If your code is invoked in another application, this call to GetObject will
succeed only if Word is open. For this reason, your code should test whether
this call succeeds. If it fails with error 429, as it should if Word is not
running, you can call CreateObject to open Word, as in the following example.
This example also shows that if the code opens a new instance of Word, it can
close it when it finishes.

Const Error_NotRunning = 429
Dim appWord As Object
Dim newInstance As Boolean

On Error Resume Next
Set appWord = GetObject(, "Word.Application")
If Err.Number = Error_NotRunning Then
Set appWord = CreateObject("Word.Application")
MsgBox "A new instance of Word was created."
newInstance = True
Else
MsgBox "An open instance of Word is being used."
newInstance = False
End If
On Error GoTo 0
appWord.Visible = True

' Your other code goes here.

If newInstance = True Then
appWord.Quit
End If
Set appWord = Nothing
 
E

Eileen

Thank you for the clarification. Yes, I am running the code from Word. I
will try your suggestions.
 
E

Eileen

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
trouble setting the newly opened document to "FromDoc" without it. Did I
miss something?
 
F

Fumei2 via OfficeKB.com

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
trouble setting the newly opened document to "FromDoc" without it. Did I
miss something?
Hi Eileen,
[quoted text clipped - 98 lines]
 
F

Fumei2 via OfficeKB.com

Sorry, I forgot it was an object, and therefore needs the brackets.

Set FromDoc = Documents.Open(strDocName)
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]
 
D

Doug Robbins - Word MVP

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

Fumei2 via OfficeKB.com said:
Sorry, I forgot it was an object, and therefore needs the brackets.

Set FromDoc = Documents.Open(strDocName)
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
 
E

Eileen

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

Fumei2 via OfficeKB.com said:
Sorry, I forgot it was an object, and therefore needs the brackets.

Set FromDoc = Documents.Open(strDocName)
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
 
D

Doug Robbins - Word MVP

If you are running the code from Word, why would there not be an instance of
Word when the code get to the msoFileDialogSaveAs.

Just what is it that you are trying to do - in plain English, not VBA?

--
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

Eileen said:
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

Fumei2 via OfficeKB.com said:
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
 
E

Eileen

After closing the FromDoc, I am trying to do a save as on the ToDoc but I
always get a compile error at msoFileDialogSaveAs saying it can't find
project or
library"
--
Thanks for your help.
Eileen


Doug Robbins - Word MVP said:
If you are running the code from Word, why would there not be an instance of
Word when the code get to the msoFileDialogSaveAs.

Just what is it that you are trying to do - in plain English, not VBA?

--
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

Eileen said:
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
 
D

Doug Robbins - Word MVP

That is not plain enough for me. In plain English, without any reference to
vba terms, what is that you want to do?

--
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

Eileen said:
After closing the FromDoc, I am trying to do a save as on the ToDoc but I
always get a compile error at msoFileDialogSaveAs saying it can't find
project or
library"
--
Thanks for your help.
Eileen


Doug Robbins - Word MVP said:
If you are running the code from Word, why would there not be an instance
of
Word when the code get to the msoFileDialogSaveAs.

Just what is it that you are trying to do - in plain English, not VBA?

--
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

Eileen said:
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


:

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
 
E

Eileen

Document one has the vba module. From Document one i open document two. I
get some information from document two and place it in document one. Then I
close document two. After closing document two, I save a version of document
one using file save as.

--
Thanks for your help.
Eileen


Doug Robbins - Word MVP said:
That is not plain enough for me. In plain English, without any reference to
vba terms, what is that you want to do?

--
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

Eileen said:
After closing the FromDoc, I am trying to do a save as on the ToDoc but I
always get a compile error at msoFileDialogSaveAs saying it can't find
project or
library"
--
Thanks for your help.
Eileen


Doug Robbins - Word MVP said:
If you are running the code from Word, why would there not be an instance
of
Word when the code get to the msoFileDialogSaveAs.

Just what is it that you are trying to do - in plain English, not VBA?

--
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

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


:

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
 
D

Doug Robbins - Word MVP

Use:

Dim ToDoc As Document, FromDoc As Document
Dim strNewName As String
Set ToDoc = ActiveDocument
With Dialogs(wdDialogFileOpen)
If .Show <> -1 Then
MsgBox "No file selected"
Exit Sub
End If
End With
'set newly opened doc as "FromDoc"
Set FromDoc = ActiveDocument
With FromDoc
strNewName = Replace(.FullName, .Name, "New " & .Name)
' Get something from FromDoc
.Close wdDoNotSaveChanges
End With
With ToDoc
' Put what ever it was into ToDoc
'Save ToDoc with the new name
.SaveAs strNewName
End With


--
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

Eileen said:
Document one has the vba module. From Document one i open document two.
I
get some information from document two and place it in document one. Then
I
close document two. After closing document two, I save a version of
document
one using file save as.

--
Thanks for your help.
Eileen


Doug Robbins - Word MVP said:
That is not plain enough for me. In plain English, without any reference
to
vba terms, what is that you want to do?

--
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

Eileen said:
After closing the FromDoc, I am trying to do a save as on the ToDoc but
I
always get a compile error at msoFileDialogSaveAs saying it can't find
project or
library"
--
Thanks for your help.
Eileen


:

If you are running the code from Word, why would there not be an
instance
of
Word when the code get to the msoFileDialogSaveAs.

Just what is it that you are trying to do - in plain English, not VBA?

--
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

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


:

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
 
D

Doug Robbins - Word MVP

I see they are appearing here, but not in the NNTP newsgroups for some reason.

Odd however as responses to other posts in microsoft.public.word.vba.general
are appearing in the NNTP newsgroups.

Doug Robbins - Word MVP said:
For some reason, my replies to your latest post are not getting through,
Here is what I had posted in response to that post:

Use:

Dim ToDoc As Document, FromDoc As Document
Dim strNewName As String
Set ToDoc = ActiveDocument
With Dialogs(wdDialogFileOpen)
If .Show <> -1 Then
MsgBox "No file selected"
Exit Sub
End If
End With
'set newly opened doc as "FromDoc"
Set FromDoc = ActiveDocument
With FromDoc
strNewName = Replace(.FullName, .Name, "New " & .Name)
' Get something from FromDoc
.Close wdDoNotSaveChanges
End With
With ToDoc
' Put what ever it was into ToDoc
'Save ToDoc with the new name
.SaveAs strNewName
End With


--
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

Eileen said:
After closing the FromDoc, I am trying to do a save as on the ToDoc but I
always get a compile error at msoFileDialogSaveAs saying it can't find
project or
library"
--
Thanks for your help.
Eileen


Doug Robbins - Word MVP said:
If you are running the code from Word, why would there not be an instance
of
Word when the code get to the msoFileDialogSaveAs.

Just what is it that you are trying to do - in plain English, not VBA?

--
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

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


:

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
 
E

Eileen

thank you for the information, Doug.
--
Thanks for your help.
Eileen


Doug Robbins - Word MVP said:
I see they are appearing here, but not in the NNTP newsgroups for some reason.

Odd however as responses to other posts in microsoft.public.word.vba.general
are appearing in the NNTP newsgroups.

Doug Robbins - Word MVP said:
For some reason, my replies to your latest post are not getting through,
Here is what I had posted in response to that post:

Use:

Dim ToDoc As Document, FromDoc As Document
Dim strNewName As String
Set ToDoc = ActiveDocument
With Dialogs(wdDialogFileOpen)
If .Show <> -1 Then
MsgBox "No file selected"
Exit Sub
End If
End With
'set newly opened doc as "FromDoc"
Set FromDoc = ActiveDocument
With FromDoc
strNewName = Replace(.FullName, .Name, "New " & .Name)
' Get something from FromDoc
.Close wdDoNotSaveChanges
End With
With ToDoc
' Put what ever it was into ToDoc
'Save ToDoc with the new name
.SaveAs strNewName
End With


--
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

Eileen said:
After closing the FromDoc, I am trying to do a save as on the ToDoc but I
always get a compile error at msoFileDialogSaveAs saying it can't find
project or
library"
--
Thanks for your help.
Eileen


:

If you are running the code from Word, why would there not be an instance
of
Word when the code get to the msoFileDialogSaveAs.

Just what is it that you are trying to do - in plain English, not VBA?

--
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

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


:

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
 

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