PDA

View Full Version : timespan in vb6


Pages : 1 [2]

Bond
06-10-2004, 07:34 AM
In your VB project, add a reference to "Microsoft Word x.0 Object Library" where x is the version of Word that is installed (9 = 97, 10 = 2000, 11 = 2002/XP). Add this reference by clicking the Project menu, then selecting References. Then, select the one mentioned above and click OK.

Now, you will be able to use the Word object library and the intellisense features to make life easier. For example, in your code, add something like this:

Dim w as Word.Application
Set w = New Word.Application

As you type, VB's intellisense should allow you to see the Word object library and the available choices.

Now, add this:

Dim doc as Word.Document
Set doc = w.Documents.Add

Again, the intellisense feature should guide you through this.

Finally, type:

doc.PrintOut

and you will see the available parameters (Range, From, To, Copies, Pages, etc.). You don't need to specify ALL of them -- just the ones you plan to use. For example:

doc.PrintOut Copies:=1, Pages:=1

or whatever is needed.

To see all of Word's available objects/methods/properties, press the F2 key to bring up the Object Browser. Select "Word" from the list of libraries in the upper left corner of the window, then select "Document" from the list of objects in the left pane. "PrintOut" should be a method in the right pane.

The Object Browser is convenient for seeing a library's objects, enums, etc., as well as an object's methods and properties. However, it won't tell you much about how to use them. You will have to consult the VB section in Word itself to find out more. Try opening Word, then hit Alt+F11 to bring up the VBA editor, then hit F1 to bring up help.

Also note that in the example above, we never actually add any text to the document! You're just bringing up a blank document and printing it. You will need to add your text to the doc first.

Zero Tolerance
06-10-2004, 07:56 AM
Bond....thanks for the 411

I am not sure if this is gonna be a viable option afterall. When reading you on having to select which version of word is installed is where I think is gonna kill me.

You see this program package will be installed on probably close to 50 computers throughout our 3 locations. So there are machines that are running very old versions of word...and some that are using Office 2k3.....sooooooooo unless there is a generic tag for that....or one that is universal.....then I will just have to go with how I have it already coded.

Thanks Again...you have been a BIG help!

sssssssssssBANG!

Bond
06-11-2004, 01:10 PM
It really doesn't matter which version they are running, to an extent, anyway. YOU select the reference (a.k.a, type library) in YOUR project and code using it. As long as the names of the type id's/object/methods/properties matchup, then you're good to go. And I would think Microsoft would be smart enough to make that happen.

For instance:

dim w
set w= createobject("word.application")
w.visible = true

will launch Word no matter if it's Word 2000, XP, 2003, or whatever. I'm not sure what version of Word first allowed the use of Automation (or OLE), but I would think you're probably safe all the way back to 97.

Zero Tolerance
06-11-2004, 01:21 PM
Cool....I was thinking that same thing after I posted simply because I have tested the proggy on a couple of different machines with different versions of word or office on them and it works fine on them all so far

I have coded it like this...
' Creats MS Word object
Set objWord = CreateObject("Word.Basic")
objWord.AppShow
objWord.FileNewdefault
objWord.FontSize 14
objWord.Insert " XXXXXXXXXXXX Progress Notes" & vbNewLine & vbNewLine
objWord.FontSize 10
objWord.Insert "CLIENT NAME: " & txtClientName.Text & " " & "CASE NUMBER: " & txtCaseNumber.Text & vbNewLine & vbNewLine
objWord.FontSize 10

so forth...so on.....and on.....

this has been working fine....so I am sure I can just edit it to require a password...or even not let word open at all.

Since my last post...one of the exectutive staff here likes word to be open so the Case Managers can actually use the spell check and so forth b4 printing....it was just the idea of someone saving a file and then changing it later is what they didnt want to happen. But they cant have it both ways...so they will just have to do an SOP on how to use the software

Thanks for all of your help Bond....you have been great!

Bond
06-11-2004, 02:44 PM
Anytime.