Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 25th, 2007, 04:02 PM
Registered User
Join Date: Feb 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamically add objects based on Word Bookmarks

I am trying to build a simple template engine that will do the following:

1) Open a word file that I have already inserted a series of bookmarks into.

2) Read through the file and count up the # of bookmarks.

3) Dynamically add to the main panel a series of labels and text boxes named after each bookmark found in the document.

4) Use the input from the text boxes to fill out the template (replace the bookmark text with the text from the text box.

I can open the file, read it, count the bookmarks, and get their names. I even understand how to replace the text, but I am having trouble creating the labels and boxes and adding them to the panel. Below is my code:
Public Class Form1

    Private Sub btnFindFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindFile.Click
        With OpenFileDialog1
            If Windows.Forms.DialogResult.OK Then
                Dim theFileName As String = .FileName
                Dim objWord As Word.Application
                objWord = New Word.Application
                objWord.Visible = True
                Dim docToChange As Word.Document
                docToChange = objWord.Documents.Open(theFileName)
                Dim bookmarks As Word.Bookmarks = docToChange.Bookmarks
                Dim countBookmarks As Integer = bookmarks.Count
                Dim counter As Integer = 1
                Dim textForDisplay As String
                While counter <= countBookmarks
                    textForDisplay = docToChange.Bookmarks(counter).Name
                    counter = counter + 1
                    Dim newLabel As New Label
                    newLabel.Name = textForDisplay
                    newLabel.Visible = True
                    newLabel.Text = textForDisplay
                End While
            End If
        End With
    End Sub
End Class
Thank you for all your help. - Adam
Reply With Quote
  #2 (permalink)  
Old February 26th, 2007, 02:20 AM
Authorized User
Join Date: Sep 2003
Location: Delhi, Delhi, India.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prabodh_mishra

Visit http://support.microsoft.com/kb/190670/en-us

Reply With Quote
  #3 (permalink)  
Old February 27th, 2007, 03:57 AM
Registered User
Join Date: Feb 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for the tip, but it still doesn't seem to offer any help. A lot of the code isn't even supported in VB 2005. Does anyone know of nay other online tutorial I could look at given the specs I outlined above. I usually do web stuff with php, and I know it would be so easy in PHP, but I need to work with Word files. Thanks for the help - Adam
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form and bookmarks in Word paul20091968 Word VBA 0 May 16th, 2006 09:09 AM
Automate the process of creation bookmarks in word manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 1st, 2006 10:09 AM
add a image as your 'avatar' for bookmarks crmpicco HTML Code Clinic 4 September 30th, 2005 03:51 AM
Replacing Word Bookmarks from VB pavel Pro VB 6 0 May 3rd, 2004 09:20 AM

All times are GMT -4. The time now is 01:30 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.