Results 1 to 11 of 11

Thread: Barkin' up the wrong tree?

  1. #1

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237

    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?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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?

  3. #3

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    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.

  4. #4

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    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?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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:
    1. Dim WordObject As Word.Application
    2. Set WordObject = CreateObject("Word.Application")
    3.  
    4.      With WordObject
    5.      .Documents.Open ("c:\program files\qcap\transmove.doc")
    6.      .ActiveDocument.Bookmarks("transtype").Select
    7.      ' reapply the boomark name to the selection
    8.      '.ActiveDocument.Bookmarks.Add Name:="First",Range:=Selection.Range
    9.      .ActiveDocument.Bookmarks("fromlocation").Select
    10.      .Selection.Text = (lblMoveFrom.Caption)
    11.      .ActiveDocument.Bookmarks("tolocation").Select
    12.      .Selection.Text = (lblMoveTo.Caption)
    13.      .ActiveDocument.Bookmarks("numbers").Select
    14.      .Selection.Text = (txtStatus.Text)
    15.      .ActiveDocument.Bookmarks("preparedby").Select
    16.      .Selection.Text = (UCase(UserAccount))
    17.      .ActiveDocument.Bookmarks("comments").Select
    18.      .Selection.Text = (txtComments.Text)
    19.      .ActiveDocument.Bookmarks("movedate").Select
    20.      .Selection.Text = (Today)
    21.     End With
    22.    WordObject.Visible = False
    23.        WordObject.ActiveDocument.PrintOut Background:=False
    24.        WordObject.ActiveDocument.SaveAs FileName:="x.doc"
    25.        ' setting the printing to background will display the document
    26.        ' on the screen while it is being printed
    27.        ' WordObject.Documents.Close '("c:\program files\qcap\transmove.doc")
    28.     WordObject.Application.Documents.Close
    29.     Set WordObject = Nothing
    Any help at all?

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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.

  7. #7

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    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?

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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.

  10. #10

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    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!!

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Thumbs up

    No problem. Let me know how it works out for you!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width