I'm using WOrd and Excel 2003. I'm trying to open a Word document
with the following code. I get an error on the line that should
return the FileNameInfo. It's just a message box with no text and an
X in a red circle - no Debug, just Okay and the code stops. Yes, I
have a reference to the Word library.

What did I do wrong?

Ed

'***********************

Dim bolAgain As Boolean
bolAgain = False
Stop
On Error Resume Next
Set WdAp = Word.Application
If WdAp Is Nothing Then
Set WdAp = New Word.Application
End If
On Error GoTo 0

WdAp.Visible = True

Set WdDlg = WdAp.Dialogs(wdDialogFileOpen)

Do
With WdDlg
If .Display <> -1 Then
strWdDoc = ""
Else
strWdDoc = WordBasic.FileNameInfo$(.Name, 1) '<< error here!!
End If
End With

If strWdDoc = "" Then
If MsgBox("You didn't choose a document." & vbCrLf & _
"Please try again, or choose Cancel to quit.", vbOKCancel)
= vbCancel Then
Exit Sub
Else
bolAgain = True
End If
End If
Loop While bolAgain = True

Set WdDoc = WdAp.Documents.Open(strWdDoc)

RE: Error trying to open Word doc from Excel VBA by TomOgilvy

TomOgilvy
Thu May 24 10:20:01 CDT 2007

if this code is in Excel, then use

strWdDoc = Application.GetOpenFilename()

see help for additional arguments.

--
Regards,
Tom Ogilvy



"Ed" wrote:

> I'm using WOrd and Excel 2003. I'm trying to open a Word document
> with the following code. I get an error on the line that should
> return the FileNameInfo. It's just a message box with no text and an
> X in a red circle - no Debug, just Okay and the code stops. Yes, I
> have a reference to the Word library.
>
> What did I do wrong?
>
> Ed
>
> '***********************
>
> Dim bolAgain As Boolean
> bolAgain = False
> Stop
> On Error Resume Next
> Set WdAp = Word.Application
> If WdAp Is Nothing Then
> Set WdAp = New Word.Application
> End If
> On Error GoTo 0
>
> WdAp.Visible = True
>
> Set WdDlg = WdAp.Dialogs(wdDialogFileOpen)
>
> Do
> With WdDlg
> If .Display <> -1 Then
> strWdDoc = ""
> Else
> strWdDoc = WordBasic.FileNameInfo$(.Name, 1) '<< error here!!
> End If
> End With
>
> If strWdDoc = "" Then
> If MsgBox("You didn't choose a document." & vbCrLf & _
> "Please try again, or choose Cancel to quit.", vbOKCancel)
> = vbCancel Then
> Exit Sub
> Else
> bolAgain = True
> End If
> End If
> Loop While bolAgain = True
>
> Set WdDoc = WdAp.Documents.Open(strWdDoc)
>
>

Re: Error trying to open Word doc from Excel VBA by Helmut

Helmut
Thu May 24 11:06:01 CDT 2007

Hi everybody,

strange enough, the code,
as it was posted, works perfectly here and now.

Though, I wonder about Excel knowing Wordbasic.

>strWdDoc = WordBasic.FileNameInfo$(.Name, 1)

But here and now, it works as it is.

I would have coded:

strWdDoc = WdAp.WordBasic.FileNameInfo$(.Name, 1)

?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


Re: Error trying to open Word doc from Excel VBA by Ed

Ed
Thu May 24 11:34:08 CDT 2007

On May 24, 8:20 am, Tom Ogilvy <TomOgi...@discussions.microsoft.com>
wrote:
> if this code is in Excel, then use
>
> strWdDoc = Application.GetOpenFilename()
>

Thank you, Tom!! That was it!

Ed


Re: Error trying to open Word doc from Excel VBA by Ed

Ed
Thu May 24 11:44:37 CDT 2007

On May 24, 9:06 am, Helmut Weber <nbhymsjxd...@mailinator.com> wrote:
> Hi everybody,
>
> strange enough, the code,
> as it was posted, works perfectly here and now.
>
> Though, I wonder about Excel knowing Wordbasic.
>
> >strWdDoc = WordBasic.FileNameInfo$(.Name, 1)

D'oh!! I should have thought of that! That's what happens when you
cut and paste and don't proof!

Ed


Re: Error trying to open Word doc from Excel VBA by Perry

Perry
Tue May 29 12:26:15 CDT 2007

Heads up on:
Application.FileDialog() from Office XP up (so both Excel- as well as Word
2003)
check out
http://support.microsoft.com/kb/288543

Dim fd As FileDialog
Set fd = Application.FileDialog()
...bla

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE


"Ed" <prof_ofwhat@yahoo.com> schreef in bericht
news:1180019117.708942.173730@p77g2000hsh.googlegroups.com...
> I'm using WOrd and Excel 2003. I'm trying to open a Word document
> with the following code. I get an error on the line that should
> return the FileNameInfo. It's just a message box with no text and an
> X in a red circle - no Debug, just Okay and the code stops. Yes, I
> have a reference to the Word library.
>
> What did I do wrong?
>
> Ed
>
> '***********************
>
> Dim bolAgain As Boolean
> bolAgain = False
> Stop
> On Error Resume Next
> Set WdAp = Word.Application
> If WdAp Is Nothing Then
> Set WdAp = New Word.Application
> End If
> On Error GoTo 0
>
> WdAp.Visible = True
>
> Set WdDlg = WdAp.Dialogs(wdDialogFileOpen)
>
> Do
> With WdDlg
> If .Display <> -1 Then
> strWdDoc = ""
> Else
> strWdDoc = WordBasic.FileNameInfo$(.Name, 1) '<< error here!!
> End If
> End With
>
> If strWdDoc = "" Then
> If MsgBox("You didn't choose a document." & vbCrLf & _
> "Please try again, or choose Cancel to quit.", vbOKCancel)
> = vbCancel Then
> Exit Sub
> Else
> bolAgain = True
> End If
> End If
> Loop While bolAgain = True
>
> Set WdDoc = WdAp.Documents.Open(strWdDoc)
>