|
-
Sep 7th, 2007, 05:57 PM
#1
Thread Starter
Lively Member
open word file
hello,
i tried using these codes
Dim objWord As Word.Application
Set objWord = New Word.Application
objWord.Visible = True
objWord.Documents.Open " & App.Path & \HelpFile.doc"
to open a word file but it doesnt seem to work?
will appreciate any help.
thanks.
Last edited by binbpk; Sep 7th, 2007 at 11:58 PM.
-
Sep 7th, 2007, 08:03 PM
#2
Hyperactive Member
Re: open word file
Why dont you just use the insertable control for word documents?
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 08:39 PM
#3
Thread Starter
Lively Member
-
Sep 7th, 2007, 08:43 PM
#4
Hyperactive Member
Re: open word file
yup, goto the project menu, click components, click insertable objects, there should be a ms word one there I think...
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 08:49 PM
#5
Thread Starter
Lively Member
Re: open word file
how do i drop this on the mdi form?
-
Sep 7th, 2007, 08:52 PM
#6
Hyperactive Member
Re: open word file
well, you cont put it on the mdi form, mdi forms can only have toolbars, etc. you will have to put it on the main mdi child which you just draw it on there, like you would anything else...
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 08:55 PM
#7
Thread Starter
Lively Member
Re: open word file
this actually works when i put in C:....
i think there must be something wrong with the other lines in here:
objWord.Documents.Open " & App.Path & \HelpFile.doc"
how do you write it when you want your application to be able to open a file regardless of where its placed in?
-
Sep 7th, 2007, 08:58 PM
#8
Hyperactive Member
Re: open word file
I cant help you with that, I have no Idea...
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 09:17 PM
#9
Re: open word file
It's better to use ShellExecute if you want to open a document in the program that reads that document type.
Code:
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Public Function RunFile(pstrFile As String, Optional ByVal pstrDefaultFolder As String) As Long
Const SW_SHOW = 1
Dim lngPos As Long
Dim lngDesktop As Long
If Len(pstrDefaultFolder) = 0 Then
lngPos = InStrRev(pstrFile, "\")
If lngPos > 0 Then pstrDefaultFolder = Left$(pstrFile, lngPos - 1)
End If
lngDesktop = GetDesktopWindow()
RunFile = ShellExecute(lngDesktop, "Open", pstrFile, "", pstrDefaultFolder, SW_SHOW)
End Function
Sample usage:
RunFile App.Path & "\HelpFile.doc"
Note that this works for any document type; not just word. It is the code equivalent to double-clicking a file from an explorer window.
-
Sep 7th, 2007, 09:20 PM
#10
Re: open word file
try this line before the open:
msgbox App.Path & \HelpFile.doc"
looks to me like a simple error (assuming you copied it correctly)
should be app.path & "\helpfile.doc"
people always overlook the obvious...
-
Sep 7th, 2007, 09:40 PM
#11
Thread Starter
Lively Member
Re: open word file
i tried this but it still does not work.
objWord.Documents.Open App.Path & "\HelpFile.doc"
-
Sep 7th, 2007, 11:04 PM
#12
Re: open word file
show us what your app.path is. It may already have the \ on the end for example. Also you will annoyingly get different results for app.path depending on whether the program is compiled or not.
-
Sep 7th, 2007, 11:07 PM
#13
Re: open word file
try
objWord.Documents.Add App.Path & "\HelpFile.doc"
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 7th, 2007, 11:35 PM
#14
Thread Starter
Lively Member
Re: open word file
 Originally Posted by westconn1
try
objWord.Documents.Add App.Path & "\HelpFile.doc"
nope, still doesnt work. could it be because i'm using word 2007?
it says user defined type not defined.
Last edited by binbpk; Sep 7th, 2007 at 11:40 PM.
-
Sep 7th, 2007, 11:36 PM
#15
Thread Starter
Lively Member
Re: open word file
 Originally Posted by Lord Orwell
show us what your app.path is. It may already have the \ on the end for example. Also you will annoyingly get different results for app.path depending on whether the program is compiled or not.
it's in my documents folder so it reads:
C:\Documents and Settings\User\My Documents\College\Applied Communication Technology\Assignment\CPMS
-
Sep 7th, 2007, 11:43 PM
#16
Re: open word file
so that's what you saw when you did a msgbox(app.path) or what you think it should be?
-
Sep 7th, 2007, 11:47 PM
#17
Re: open word file
try pasting in the full path
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 7th, 2007, 11:48 PM
#18
Thread Starter
Lively Member
Re: open word file
 Originally Posted by Lord Orwell
so that's what you saw when you did a msgbox(app.path) or what you think it should be?
you mean it's supposed to read the path to my documents folder?
-
Sep 7th, 2007, 11:58 PM
#19
Thread Starter
Lively Member
Re: open word file
ok managed to get it to work. i did not select the word object library from the references.
thank you so much for all your help.
appreciate it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|