Macros in ThisDocument

H

Heinz

Hi together,

i want to place some checkboxes in a new document using a
Template. The checkboxes are placed in a table. The Code
for the checkboxes i want to place in ThisDocument. When i
run the Template windword will crash with the errormesage:

The instruction at "<address>" referended memory
at "<adress>". The memory could not be read.

I can write any comment to ThisDocument. But when i use
the code for the checkboxes, this happens. The code of the
template is:

' ******************************************************

Public Sub subfillLine(txtTask, txtTaskMarker)

Dim shp

Selection.InsertAfter txtTask ' This is only Text
Selection.MoveRight unit:=wdCell



ActiveDocument.VBProject.VBComponents"ThisDocument").CodeMo
dule.AddFromString _
" Sub chk" & txtTaskMarker & "_Click()" _
& vbCr & " MsgBox " & """" & "Hello World" & """" _
& vbCr & " End Sub"

Set shp =
Selection.InlineShapes.AddOLEControlClassType:="Forms.Check
Box.1")
With shp.OLEFormat.Object
.Name = "chk" & txtTaskMarker
.Width = 10
.Height = 10
.Caption = ""
End With


Selection.MoveRight unit:=wdCell
Selection.Bookmarks.Add "book" & txtTaskMarker
Selection.MoveDown unit:=wdLine
Selection.MoveLeft unit:=wdCell
Selection.MoveLeft unit:=wdCell
End Sub
' ******************************************************
Perhaps somone knows, what i' m doing wrong or has another
workaround.

Thx 4 help
 
W

Word Heretic

G'day "Heinz" <[email protected]>,

Are you calling this from an autoopen? If so, call it using an
application.ontime command


Heinz said:
Hi together,

i want to place some checkboxes in a new document using a
Template. The checkboxes are placed in a table. The Code
for the checkboxes i want to place in ThisDocument. When i
run the Template windword will crash with the errormesage:

The instruction at "<address>" referended memory
at "<adress>". The memory could not be read.

I can write any comment to ThisDocument. But when i use
the code for the checkboxes, this happens. The code of the
template is:

' ******************************************************

Public Sub subfillLine(txtTask, txtTaskMarker)

Dim shp

Selection.InsertAfter txtTask ' This is only Text
Selection.MoveRight unit:=wdCell



ActiveDocument.VBProject.VBComponents"ThisDocument").CodeMo
dule.AddFromString _
" Sub chk" & txtTaskMarker & "_Click()" _
& vbCr & " MsgBox " & """" & "Hello World" & """" _
& vbCr & " End Sub"

Set shp =
Selection.InlineShapes.AddOLEControlClassType:="Forms.Check
Box.1")
With shp.OLEFormat.Object
.Name = "chk" & txtTaskMarker
.Width = 10
.Height = 10
.Caption = ""
End With


Selection.MoveRight unit:=wdCell
Selection.Bookmarks.Add "book" & txtTaskMarker
Selection.MoveDown unit:=wdLine
Selection.MoveLeft unit:=wdCell
Selection.MoveLeft unit:=wdCell
End Sub
' ******************************************************
Perhaps somone knows, what i' m doing wrong or has another
workaround.

Thx 4 help

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email (e-mail address removed)
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top