|
-
Nov 20th, 2001, 01:21 PM
#1
Thread Starter
Addicted Member
Barkin' up the wrong tree?
Hi all
I have a Theory question:
I want to build a word document that has a bunch of neat stuff on it, and then add information that is stored in my VB program,
I have been looking into OLE Containers, but it looks like that looks like it takes information from Word, not PUT info in.
It feels like I'm barking up the wrong tee, or am I on the right track. Could somebody point me in the right direction. please?
-
Nov 20th, 2001, 01:41 PM
#2
My approach to this would be to put all of my "neat stuff" into a richtextbox on my VB screen, and then open up a blank Word document, and dump my richtextbox contents into it.
What, specifically, does the scope of your project call for?
-
Nov 20th, 2001, 01:53 PM
#3
Thread Starter
Addicted Member
well my "neat stuff" consists of:
Some graphics, information (stored in UDT's in my VB Program)
the information is mostly strings with come currency data types.
The information must be set up in a certin way.
eg..
Total Information
8945 45 $1.45
8978 82 $ 2.03
8998 43 $1.41
all of the information would have to be pre formatted for a certin font, Size, and Bold
What I'm trying to do is make a template, have my VB Program call that template and then send all of the Important information to it, and then have VB do all of the graphical formatting.
-
Nov 20th, 2001, 02:22 PM
#4
Thread Starter
Addicted Member
Ok here's a better way of wording it.
I am going to create a Template document, On this template document I'm going to have textboxes, Imageboxes and whatever else to make it look the way I want to. now for the question:
Can I call a specific word document from VB and then call specific Private Sub's created by myself to properly format the information. or am I getting further off base?
-
Nov 20th, 2001, 02:27 PM
#5
I would stick with the RichTextBox for the VB template. You can do the font, size, bold etc with this control. The Word document should contain bookmarks that, in turn, can be used by VB to tell Word where to place what.
I've never tried dumping the contents of an Image before, but I don't, theoritically, see why that would be a problem. Here is some sample code that I dug out of one of my projects.
VB Code:
Dim WordObject As Word.Application
Set WordObject = CreateObject("Word.Application")
With WordObject
.Documents.Open ("c:\program files\qcap\transmove.doc")
.ActiveDocument.Bookmarks("transtype").Select
' reapply the boomark name to the selection
'.ActiveDocument.Bookmarks.Add Name:="First",Range:=Selection.Range
.ActiveDocument.Bookmarks("fromlocation").Select
.Selection.Text = (lblMoveFrom.Caption)
.ActiveDocument.Bookmarks("tolocation").Select
.Selection.Text = (lblMoveTo.Caption)
.ActiveDocument.Bookmarks("numbers").Select
.Selection.Text = (txtStatus.Text)
.ActiveDocument.Bookmarks("preparedby").Select
.Selection.Text = (UCase(UserAccount))
.ActiveDocument.Bookmarks("comments").Select
.Selection.Text = (txtComments.Text)
.ActiveDocument.Bookmarks("movedate").Select
.Selection.Text = (Today)
End With
WordObject.Visible = False
WordObject.ActiveDocument.PrintOut Background:=False
WordObject.ActiveDocument.SaveAs FileName:="x.doc"
' setting the printing to background will display the document
' on the screen while it is being printed
' WordObject.Documents.Close '("c:\program files\qcap\transmove.doc")
WordObject.Application.Documents.Close
Set WordObject = Nothing
Any help at all?
-
Nov 20th, 2001, 02:29 PM
#6
You must have posted your last post while I was constructing mine. Keep all controls on your VB form. All your need on your Word document are the bookmarks, and whatever header/footer information you want.
-
Nov 20th, 2001, 02:44 PM
#7
Thread Starter
Addicted Member
this is my first attempt at playing around with something like this, so it is a bit overwhelming. I'm gonna play around with this a bit. Correct me if I'm wrong, but Do i have to create texboxes and imgageboxes in my word document and in thoes boxes is where i put the bookmarks?
-
Nov 20th, 2001, 03:01 PM
#8
No, no. You don't put ANY controls on your Word document except the actual bookmarks. The bookmarks aren't visible at run time (if there is such a thing as run time in Word). I forgot what menu item bookmarks are under, but open a Word document, and go through its menu. You will find them. Each bookmark will be given a unique name. Then, you just tell VB that you want the contents of Text1.Text to be placed at bookmark whatever.
Before doing this on a large scale, start a new test project. Just use a couple of text boxes, and put your first name in one, and your last name in the other. Then open a Word document, and create a book mark for your first name and your last name. Grab a few lines of the code that I gave you and play around with having VB pass your first and last name to a Word document. Once you get pretty comfortable with that, move on to your actual project.
-
Nov 20th, 2001, 03:04 PM
#9
Actually, upon momentary reflection, let me briefly amend what I just posted.
Don't use standard text boxes, use a couple of richtextboxs in your test project for your first and last name. Then, once you get VB to pass the info along to Word, go back an play with formatting your name within the text boxes. Play with the Bold, and font, and size, and stuff like that. VB should pass along the contents, in its formatted style, of the richtextbox to Word with no problem.
-
Nov 20th, 2001, 03:10 PM
#10
Thread Starter
Addicted Member
Wicked!!!
I was setting all of this up while you did your last post, now that I got the point, it works pretty good. Now I just have to play around with multiple entries into the same bookmark......
I guess I could do text1.text = text1.text & (whatever)
I'll let you know how this works out!!
Thanks a Million!!
-
Nov 20th, 2001, 03:34 PM
#11
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
|