Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inheritance Problem

Status
Not open for further replies.

simian336

Programmer
Sep 16, 2009
723
US
I have some code that I need to repeat so I put it in a sub. But I think when it goes to the sub it is loosing the inheritance to the Word app class. The error is "invalid or unqualified reference".

Any idea how to keep the keep the class in the sub?

Thanks

Simi


Private Sub Command8_Click()

Dim wdApp As Word.Application
Set wdApp = New Word.Application

With wdApp
.Visible = True
.Activate
.Documents.Add

With .Selection
.Font.Name = "Calibri"
.Font.Size = 16
.BoldRun
.TypeText Me.jobtitle
.BoldRun
.TypeParagraph
End With

BulletedList ("This is one of my Items")

With Selection
.TypeText "Date Revised: " + Format(Now, "MMMM d, yyyy")
End With
End With

End Sub


Public Sub BulletedList(MyItem As String)
' ********************************************************
' * List with Blue Box
' ********************************************************
'Pre Spaces
With Selection
.Font.Color = RGB(91, 155, 213)
.TypeText " "
End With
'Box with Post Spaces
With Selection
.Font.Color = RGB(91, 155, 213)
.InsertSymbol Font:="Wingdings", CharacterNumber:=167, Unicode:=True
.TypeText " "
End With
'List text
With .Selection 'Error here
.Font.Color = wdBlack
.Font.Name = "Calibri"
.Font.Size = 11
.BoldRun
.TypeText MyItem
.BoldRun
.TypeParagraph
End With
' ********************************************************

End Sub
 
You have to use full qualified object names, eg in Command8_Click instead of
With Selection
use
With .Selection
Furthermore the BulletedList procedure has no idea of the wdApp object, so I suggest to pass it as paramater.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hey PHV,

I guess I am not getting the syntax correct for the passing the wdApp object as a paramater.

Would you happen to know what it should look like?

Thanks

Simi
 
Try:

Code:
Call BulletedList ("This is one of my Items"[blue], wdApp[/blue])
...

Public Sub BulletedList(MyItem As String[blue], ByRef MyWord As Word.Application[/blue])
' ********************************************************
' * List with Blue Box
' ********************************************************
'Pre Spaces[blue]
With MyWord[/blue]
   With [blue].[/blue]Selection
       .Font.Color = RGB(91, 155, 213)
   ...

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Humm.... that is close to what I had

Getting "Type Mismatch" error

Public Sub Command8_Click()

Dim wdapp As Word.Application
Set wdapp = New Word.Application

With wdapp
.Visible = True
.Activate
.Documents.Add

BulletedList (wdapp) 'getting type mismatch here

End With
End Sub

Public Sub BulletedList(ByRef MyWord As Word.Application)
' ********************************************************
' * List with Blue Box
' ********************************************************
'Pre Spaces


With MyWord
With .Selection
.Font.Color = wdBlack
.Font.Name = "Calibri"
.Font.Size = 11
.BoldRun
.TypeText "This is a monster test"
.BoldRun
.TypeParagraph
End With
End With
' ********************************************************

End Sub
 
Humm.... that’s interesting.

Try something like this then: move Dim statement to General Declaration

And please use code tags, it is a lot easier to read.

Code:
Option Explicit[blue]
Dim wdapp As Word.Application[/blue]

Public Sub Command8_Click()

[s]Dim wdapp As Word.Application[/s]
Set wdapp = New Word.Application

With wdapp
    .Visible = True
    .Activate
    .Documents.Add

    BulletedList [s](wdapp)[/s] 
    ...

Public Sub BulletedList(ByRef MyWord As Word.Application)

With [blue]wdapp[/blue]
    With .Selection
    ....

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top