Help: Using Word Forms/Booksmarks in Excel VBA

JDM-LTCS

New Member
Joined
Sep 7, 2006
Messages
40
Okay, my tool goes a little something like this:

In Excel, it creates an entryform where data is entered into various combobox and text fields.

The tool then opens Word, loads a pre-made template file with pre-defined bookmarks, then inserts the data from the entryform into those bookmarks.

My previous version used the insertion bookmarks and worked fine for when I was simply entering the data from the entryform at those points.

But for the next version, I need to insert the data INTO those bookmarks (ie a fillable form) so that I can then recall the data from the Word file back into the Excel tool.

Make sense so far?

Using my old code doesn't work. I receive an error message: Run-time error '438': Object doesn't support this property or method.

I've tried all sorts of combinations of code to get this to work and still not getting it right. Clearly, I'm not understanding the error message.

My code looks a little something like this:
--------------------------------------------------------------------------------
'
' Open the Word Program and load the TcubedCVR-newertoolform.dot template.
'
Set wrd = CreateObject("Word.application")
wrd.Visible = True
Set CVR = wrd.documents.Add("TcubedCVR-newertoolform.dot")
CVR.Protect Type:=2, Password:="12345"
'
' Store form fields into Word bookmarks
'
CVR.Bookmarks("TcubedTchr").Text = TcubedTchr
CVR.Bookmarks("School").Range = School
CVR.Bookmarks("VisitDate").Range.Text = Date
CVR.Bookmarks("VisitTime").Range.Text = Time
--------------------------------------------------------------------------------

You might ask yourself why am I protecting the document. Well, if I don't the text inserted replaces the bookmark. But when I protect it so that the file is a fillable form, I can manually insert text/data into the bookmarks without losing them. So I'm trying to automate that process by having the tool insert into the bookmarks the data from the fields.

Any help is appreciated! Muchos Danke!!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
To give an example of why I wanted to protect the document:
-------------------------------------------------------------------------------------
'
' Open the Word Program and load the TcubedCVR-newertoolform.dot template.
'
Set wrd = CreateObject("Word.application")
wrd.Visible = True
Set CVR = wrd.documents.Add("TcubedCVR-newertoolform.dot")
' CVR.Protect Type:=2, Password:="12345"
'
' Store form fields into Word bookmarks
'
CVR.Bookmarks("TcubedTchr").Range = TcubedTchr
CVR.Bookmarks("School").Range = School
CVR.Bookmarks("VisitDate").Range.Text = Date
CVR.Bookmarks("VisitTime").Range.Text = Time
-------------------------------------------------------------------------------------

This replaces the bookmark with the text stored in the entryform's variable I'm inputing. So I want to go from replacing to inserting.

NOTE: both .range and .range.text seems to work. /em scratches his head
 
Upvote 0
On my continual tweaking quest, this new code gives me a different error message. I can't tell if I'm digging deeper into this hole or digging myself out. =)

-------------------------------------------------------------------------------------
Set wrd = CreateObject("Word.application")
wrd.Visible = True

Set CVR = wrd.documents.Add("TcubedCVR-newertoolform.dot")

CVR.Protect Type:=2, Password:="12345"


CVR.Bookmarks.Item("TcubedTchr") = TcubedTchr
CVR.Bookmarks.Item("School") = School
CVR.Bookmarks.Item("VisitDate") = Date
CVR.Bookmarks.Item("VisitTime") = Time
-------------------------------------------------------------------------------------

And the new error message is: Run-Time error '5861': 'Name" is a read only property.
 
Upvote 0
Plan B; the Workaround Plan....

Okay, since I either no one knows how to do this or the person(s) with the answer didn't read this post, I had to come up with a Plan B.

For writing out the data/text to the Word file, I used insertion bookmarks to direct my tool where to insert the data at.

Then when it came time to pull the data out of the Word file, I used a .DOT file that used tables. I cleaned up the tables so it didn't look like tables. Then I could use a simple code of point the tool to the table.row.cell in order to pull the text/data out.


Just wanted to let others who are struggling with the same thing know what workaround I came up with.


Thanks,
 
Upvote 0

Forum statistics

Threads
1,214,559
Messages
6,120,203
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top