PDA

View Full Version : Solved: Word Automation : Give a value to an object with VB



Pleasure
09-16-2008, 04:49 AM
Hello my friends. I'm actually new in this forum. Congratulations for your hard work. Without you, people like me ... well known as "dammies", would not be able to do a lot of things.

I don't know if I have posted at the correct section. Please feel free to move my post.

My question is very simple. I'm using an activex control to create barcodes inside word document. Actually I'm willing to do this by using VBA from Ms Access.

Let's say that the barcode object name is BRC1, with the property .datatoencode, just to add the appropriate alpharethmetic for barcode encoding.

So after adding a reference to Microsoft Word 11 object library, the code I use is :


Set APWORD = New Word.Application
With APWORD
.Visible = True
.Documents.Open Filename:="c:\Test.doc"
BRC.DatatoEncode = "123123" ' <----- RunTime Error occurs here
End With
APWORD.Quit
Set APWORD = Nothing


So I get a Runtime Error 24 "Object Required". :dunno

I'm using Windows XP, Access 2003 as also Word 2003.

Do you have anything in mind to resolve this situation ??

Thank you

TonyJollans
09-16-2008, 05:24 AM
What and where is your barcode object - how have you set a reference to it? You say it's called BRC1 but the code fails to find BRC - nothing to do with Word at all as far as I can see.

Pleasure
09-16-2008, 05:48 AM
I have solved the problem.

Instead of BRC.DatatoEncode = "123123" I used

APWORD.ActiveDocument.BRC.DatatoEncode = "123123"

And now everything works just ok.

fumei
09-16-2008, 08:49 AM
This is precisely what Tony was saying. You had no object.


With APWORD
.Visible = True
.Documents.Open Filename:="c:\Test.doc"
BRC.DatatoEncode = "123123" ' <----- RunTime Error occurs here
End With



should be:

With APWORD
.Visible = True
.Documents.Open Filename:="c:\Test.doc"
.ActiveDocument.BRC.DatatoEncode = "123123"
End With

Although I do not know about the BRC1 you mention vs BRC.

Pleasure
09-17-2008, 12:47 AM
Thank you for your replies.

Actualy BRC1 and BRC is the same. I just forgot to put the "1" in the code.

Now I am trying to resolve another problem. Actually I cannot set "wrap" to "in line with text" for BRC1, with VBA code. Is it possible to do this with VBA ?

TonyJollans
09-17-2008, 01:00 AM
You have a "Shape" and you must first convert it to an "InlineShape". Use the ConvertToInlineShape method.

Pleasure
09-17-2008, 01:35 AM
You have a "Shape" and you must first convert it to an "InlineShape". Use the ConvertToInlineShape method.


Thanks for the reply TonyJollans. But I'm not familiar with the syntax of converttoinlineshape. Can you post an example to have a look ?

Pleasure
09-17-2008, 05:27 AM
Well I used

APWORD.ActiveDocument.BRC1.ConvertToInlineShape

and got the error message that object doesn't support this property or method.

Pleasure
09-17-2008, 05:55 AM
Well I finaly did it, without ConvertToInlineShape. Have a look :


For Each s In APWORD.ActiveDocument.Shapes

With s.WrapFormat
.Type = wdWrapSquare

'wdWrapInline
'wdWrapNone
'wdWrapSquare
'wdWrapThrough
'wdWrapTight
'wdWrapTopBottom

.Side = wdWrapBoth
'wdWrapBoth
'wdWrapLargest
'wdWrapLeft
'wdWrapRight

End With

's.ConvertToInlineShape
Next s



Thanks again for all the help