Passing a public object into a function

A

ASP

Hi,

I use VBA automation to control Word using Excel. In Excel, I work with a public oDocWord object which is a Word.Document. So, I understand that the public object have not to be pass into a function.

I have modified a specific Sub in order to use the same Sub in many programs. In this Sub, the oDocWord object is pass into many functions. It works but sometimes I get abnormal result in Word (ex: I produce like 20 tables but for 3 cells of a specific table, it doesn't work when I try to underline it, I go step by step and Word doesn't take it.) I had never had these issues before. It's like if the object get corrupted. I wonder if there is a known issue about this? I posted an example of the code below.

Thank you,
Alex

Example (simplified):

Public oDocWord as Word.Application

Sub Main()

Set oDocWord = ...

program

Call functionA(oDocWord, sName)

End Sub

FunctionA(oDocWord as Word.Document, sName as string)
oDocWord.Style = sName
End Function
 

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