|
-
Jul 1st, 2008, 06:36 PM
#1
Thread Starter
New Member
Help Me Please!
Hello my name is James
I work for the local Police Department, and I have been trying to learn VB. I have boughten a few books to help me learn VB, including VB for dummies. I am trying to make a program to launch 4 Word doc's. I have not even got anywhere close to being able to make one yet. So far all I can create is a program that launches and says Hi All !!!. I Am wondering if someone could write a program for us PLEASE!!! all we need the program to do is launch 4 word docs, they can all launch at the same time or 1 at a time dont matter. as long as they launch and can be printed thats all that counts.
If possible cal the program Richland Co. Felony Packet, the name of the 4 Word docs are.
Complaint Charging Offense, Warrant on Complaint, Return, and In the Municipal Court of Shelby, Ohio.
These Word Doc's are in the My Documents Folder.
I am hoping someone can help us out, this would be greatly appriciated. If you need any additional information just let me know.
Thank You All Very Much!!!!
-
Jul 1st, 2008, 10:10 PM
#2
-
Jul 1st, 2008, 11:33 PM
#3
Re: Help Me Please!
This code will work. Note that I put the ShellTest.doc & ShellTest2.doc in the Office folder because Winword.exe is not a system accessory application like Notepad, so you have to point the Shell function at both Winword and the .doc files. Yes, putting your docs in the Office folder is not convenient. Hopefully someone else has a better solution.
Code:
Option Explicit
Dim Path$
Private Sub Form_Load()
Path$ = "C:\Program Files\Microsoft Office\Office"
ChDir (Path$)
Shell "Winword.exe ShellTest.doc ShellTest2.doc", 1
End Sub
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jul 2nd, 2008, 09:55 AM
#4
Re: Help Me Please!
Well my Friends on the other side of the pond came through again. This code was supplied to me by: Martin Allen of the Martin2K group.
http://www.martin2k.co.uk/forums/ind...=0&#entry65773
I modified his code, just a tad, by putting the doc path in the variable docPath$. His code works great. Just change the doc names and add your other two docs by repeating the relevant code blocks. If your paths are different you will have to change them too!
Code:
Option Explicit
Dim wordPath$
Dim docPath$
Private Sub Command4_Click()
Dim quotes As String
quotes = Chr(34)
wordPath$ = "C:\Program Files\Microsoft Office\Office"
docPath$ = "C:\Documents and Settings\Owner\My Documents"
ChDir (wordPath$)
Shell "Winword.exe " & quotes & docPath$ & "\ShellTest1.doc" & _
quotes & " " & quotes & docPath$ & "\ShellTest2.doc" & quotes, 1
End Sub
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jul 2nd, 2008, 10:49 AM
#5
Re: Help Me Please!
James, I forgot to welcome you to the forum.
Welcome!
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jul 2nd, 2008, 04:27 PM
#6
Re: Help Me Please!
Well Chris I would never use the Shell function to open any exe with documents or files. Why, because you can't assume that Winword.exe as been installed in Program Files\Microsoft Office\Office and on which drive. Your best option is to use the ShellExecute API. That is also assuming that Office as been installed in the first place. Even with ShellExecute you need Office installed.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Jul 2nd, 2008, 05:54 PM
#7
Re: Help Me Please!
No Shell or ShellExecute. Use Word objects and methods.
Code:
Sub cmdOpenDocs_Click()
Dim wdApp As Object '--Word.Application
Dim myPath As String
Dim myDocs(1 To 4) As String
Dim i As Integer
myPath = "C:\Documents and Settings\USERID\My Documents\"
myDocs(1) = "Complaint Charging Offense.doc"
myDocs(2) = "Warrant on Complaint.doc"
myDocs(3) = "Return.doc"
myDocs(4) = "In the Municipal Court of Shelby, Ohio.doc"
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
For i = 1 To 4
wdApp.Documents.Open myPath & myDocs(i)
Next
Set wdApp = Nothing
End Sub
-
Jul 2nd, 2008, 09:49 PM
#8
Re: Help Me Please!
 Originally Posted by anhn
No Shell or ShellExecute. Use Word objects and methods.
Well yes, this also works well. I tried timing which was faster but the difference isn't worth mentioning. Any particular reason that you didn't post this in post 2?
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jul 2nd, 2008, 10:04 PM
#9
Re: Help Me Please!
OK Keith, I'll read through the multitude of posts regarding the ShellExecute API. I know there are many members, on both sides of the pond, that prefer it.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jul 2nd, 2008, 10:42 PM
#10
Re: Help Me Please!
 Originally Posted by CDRIVE
Well yes, this also works well. I tried timing which was faster but the difference isn't worth mentioning.
How did you do timing on Shell()? That is not accurate due to:
By default, the Shell function runs other programs asynchronously. This means that a program started with Shell might not finish executing before the statements following the Shell function are executed.
-
Jul 3rd, 2008, 12:04 AM
#11
Re: Help Me Please!
 Originally Posted by anhn
How did you do timing on Shell()?
I did it under strict laboratory conditions. I insured that the room temperature was a solid 25 deg C, clicked the CommandButton and counted one -onethousand....
Hey, like I said... The difference is nearly imperceptible to me.
Thanks for posting the code but I think we seem have lost the TS?! No matter though, as your code is now a part of my growing library.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jul 3rd, 2008, 12:31 AM
#12
Hyperactive Member
Re: Help Me Please!
Just if you are interested James, this can all be done in a Word document so you dont even need a separate program. Ask away if you want to know how to do it.
Slower than a crippled Vista
More buggy than a fresh XP install
Look! Down the road, some 50 miles behind the drunken snail.
It's Ubuntu!
-
Jul 3rd, 2008, 06:12 AM
#13
Re: Help Me Please!
 Originally Posted by anhn
No Shell or ShellExecute. Use Word objects and methods.
Yes but as I've said before you still need Word installed.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Jul 3rd, 2008, 06:30 AM
#14
Last edited by anhn; Jul 3rd, 2008 at 06:38 AM.
-
Jul 3rd, 2008, 06:46 AM
#15
Re: Help Me Please!
 Originally Posted by anhn
Which way you don't need Word installed?
Or you may say you can use OpenOffice or any program that can read Word documents? 
Thats why I would recommend he used ShellExecute API because it doesn't matter what file he is trying to open if there is a reference to the file extension in the registry ShellExecute will use it.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Jul 3rd, 2008, 07:13 AM
#16
Re: Help Me Please!
Another "best" advise:
"No one should use any Microsoft Word/Excel/PowerPoint/... Application Objects in VB code because you have no way to know a user has those applications installed or not.
ShellExecute API must be used instead. That is the most powerful function."
-
Jul 3rd, 2008, 02:15 PM
#17
Re: Help Me Please!
 Originally Posted by anhn
ShellExecute API must be used instead. That is the most powerful function.
Correct.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Jul 3rd, 2008, 05:30 PM
#18
Re: Help Me Please!
I've been programming with VB for 12 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
From 14 years down to 12 years!?!
Only a "14-down-to-12-years Pro" know how to use "ShellExecute API" in that "Pro" & "Correct" way.
I had only "one month non-Pro" experience, it will take me another 12 or 14 years (minus one month) to work hard with "Pro" so I can know how to use that powerful function.
Thanking you for that "Pro" advice.
-
Jul 3rd, 2008, 06:00 PM
#19
Re: Help Me Please!
 Originally Posted by anhn
From 14 years down to 12 years!?!
Thats because on this post.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Jul 3rd, 2008, 06:05 PM
#20
-
Jul 3rd, 2008, 06:36 PM
#21
Re: Help Me Please!
 Originally Posted by CDRIVE
Anhn, am I missing something here? Why all the venom? Is this a Brit - Aussie thing that a Yank wouldn't understand?
OK, that's enough for a Pro on signature.
I will learn to love ShellExecute.
Brit English & Aussie English are more closer than Yanky English.
Eh! I forgot that this thread was started by a cop. Sorry Sir (or Sorry Officer, which one is used by a Yank?).
Last edited by anhn; Jul 3rd, 2008 at 06:41 PM.
-
Jul 3rd, 2008, 08:46 PM
#22
Re: Help Me Please!
 Originally Posted by anhn
Brit English & Aussie English are more closer than Yanky English.
I was wondering when you would get around to me. Your grammar is exceeded only by your social skills! May I suggest that you consider switching from briefs to boxer shorts?
Eh! I forgot that this thread was started by a cop. Sorry Sir (or Sorry Officer, which one is used by a Yank?).
Well, I call my Uncle Frank and Mike 'Uncle Frank' and 'Uncle Mike'. I call my Cousins Bob, Ralph and Vinnie.. 'Bob', 'Ralph' and 'Vinnie'. Officers that I don't know personally I address as Officer. I realize that this may seem rather archaic to you but I exhibit respect until someone gives me a reason to do otherwise.
Anhn, please sleep on this thought. You just may realize that you're wasting your God given skills in the pursuit of verbal combat, which has no return value.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jul 3rd, 2008, 09:44 PM
#23
Re: Help Me Please!
 Originally Posted by CDRIVE
I was wondering when you would get around to me. Your grammar is exceeded only by your social skills! May I suggest that you consider switching from briefs to boxer shorts?
Well, I call my Uncle Frank and Mike 'Uncle Frank' and 'Uncle Mike'. I call my Cousins Bob, Ralph and Vinnie.. 'Bob', 'Ralph' and 'Vinnie'. Officers that I don't know personally I address as Officer. I realize that this may seem rather archaic to you but I exhibit respect until someone gives me a reason to do otherwise.
Anhn, please sleep on this thought. You just may realize that you're wasting your God given skills in the pursuit of verbal combat, which has no return value.
* Just let you know, English is not my native language even I call myself an Aussie because I am an Australian citizen and I am proud of that.
You can write 5 pages in one hour but it takes me 5 hours to write one page. I've learnt English on the streets and in factories where I worked as a manual worker (I rebuilt my life from empty hands). So for sure my writing always contains a lot of grammar and spelling misktakes.
25 years ago, when I got out of a train station, I asked the man at the ticket box "Good morning sir! Would you please tell me where the toilet is." He replied: "Pardon!". I had to repeat the question 5 times before he could understand what I said. How can I ask for that now? "Hey man, Where's the toilet!"
* An Aussie tennis star, Pat Rafter, once said something like: No where in the world we can talk to our Prime Minister just simply as "Hi John!" (for John Howard, the ex. PM, the current PM is Kevin Rudd).
* I will take your "non-Pro" advice! Keep energy to help others.
Last edited by anhn; Jul 4th, 2008 at 12:12 AM.
-
Jul 4th, 2008, 02:58 PM
#24
Thread Starter
New Member
Re: Help Me Please!
Thank you all for ur help I am sorry for not getting back sooner, i've been real busy.
the codes listed here are they everything i need to make a full app with. or just the main part of ir?
Thanks again
-
Jul 4th, 2008, 05:28 PM
#25
Re: Help Me Please!
 Originally Posted by Tigerfish1977
Are they everything Ineed to make a full app with, or just the main part of it?
That depends? What I gave you in post #4 will take a little effort on your part. On the other hand, the code that Anhn gave you uses all your variable names etc. Either one will work but Anhn's code is more ready to go for you. If your using XP you will have to modify what he marked in red. Actually, you're going to have to verify that the path exists on the machine in question. Do you know how to copy and paste code from the forum to your project?
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jul 4th, 2008, 09:07 PM
#26
Re: Help Me Please!
Since much has been said about the ShellExecute API you might as well have that too. To test this you will have to rename the ShellTest.docs with your file names and you will have to insure that path$ matches yours. Just repeat the ShellExecute lines for the other two docs that you have.
Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Dim path$
Const SW_MAXIMIZE = 3
Private Sub cmdOpenDocs_Click()
path$ = "C:\Documents And Settings\Owner\My Documents"
ShellExecute Me.hwnd, "open", path$ & "\ShellTest1.doc", vbNullString, vbNullString, SW_MAXIMIZE
ShellExecute Me.hwnd, "open", path$ & "\ShellTest2.doc", vbNullString, vbNullString, SW_MAXIMIZE
End Sub
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
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
|