Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Search via Windows API via VBA to add a file to a macro to open

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
justagrunt - 06 Apr 2007 01:40 GMT
Hi,
I've used a program (copied and pasted it from a Microsoft recommended site)
with the use of the windows API to sellect an excel spreadsheet, get is path,
with success,  when I use the same, to open a word document it gives me a
'Bad file name error.
Is there a way to use the explorer to find a word document so that it can be
used in and expression like,

Set objDocs = objWord.Documents.Add(strwordTemplate)

where

strwordTemplate

is the path to the document.

Signature

Regards
Bill

Perry - 06 Apr 2007 10:44 GMT
[strwordTemplate] does this contain the full filename?
In other words, if you run below sequence, does the messagebox popup?

If Dir(strwordTemplate) = "" Then
   MsgBox "File does not exists"
Else
   Set objDocs = objWord.Documents.Add(strwordTemplate)
End if

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE

> Hi,
> I've used a program (copied and pasted it from a Microsoft recommended
[quoted text clipped - 14 lines]
>
> is the path to the document.
justagrunt - 06 Apr 2007 23:20 GMT
Thanks Perry,
I get the message box after the API window has opened to select the file and
the selection has been made - "Bad File Name".
I will implement your valued comments and see where it takes me.
Signature

Best Regards
Bill (Happy esater from New Zealand)

> [strwordTemplate] does this contain the full filename?
> In other words, if you run below sequence, does the messagebox popup?
[quoted text clipped - 31 lines]
> >
> > is the path to the document.
Helmut Weber - 06 Apr 2007 13:41 GMT
I don't know about the explorer.
Possibly you don't need any api for what you want to do.

Try:

Sub Macro4()
Dim strFil As String
Dim strPth As String
Dim odlg As Dialog
Set odlg = Dialogs(wdDialogFileOpen)
With odlg
  .Display
  ' doubleclick filename in listbox
  strFil = .Name
  strPth = WordBasic.FileNameInfo(.Name, 5)
End With
MsgBox strPth & strFil '!
End Sub

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

justagrunt - 06 Apr 2007 23:16 GMT
Thanks Helmut,
will implement and see if it works.
Signature

Best Regards
Bill (Happy Easter from New Zealand)

> I don't know about the explorer.
> Possibly you don't need any api for what you want to do.
[quoted text clipped - 14 lines]
> MsgBox strPth & strFil '!
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.