Passing a public object into a function

Discussion in 'Word Programming' started by ASP, Mar 12, 2012.

  1. ASP

    ASP Guest

    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
     
    ASP, Mar 12, 2012
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Chris
    Replies:
    1
    Views:
    132
    Mick Hardy
    Aug 15, 2003
  2. Replies:
    0
    Views:
    152
  3. Martin Nemzow

    Preview Picture object

    Martin Nemzow, Jan 13, 2005, in forum: Word Programming
    Replies:
    0
    Views:
    140
    Martin Nemzow
    Jan 13, 2005
  4. Bradley Plett

    Passing credentials from Word to a secure site?

    Bradley Plett, Dec 29, 2006, in forum: Word Programming
    Replies:
    1
    Views:
    219
    Perry
    Jan 28, 2007
  5. VexedFist

    Passing Variables between Macros In Word

    VexedFist, Mar 23, 2007, in forum: Word Programming
    Replies:
    3
    Views:
    129
    Doug Robbins - Word MVP
    Mar 28, 2007
  6. Replies:
    1
    Views:
    1,895
  7. RAMA
    Replies:
    2
    Views:
    353
  8. Piet Linden
    Replies:
    4
    Views:
    121
    Piet Linden
    Feb 10, 2009
Loading...