User defined type could not be used as parameter to a sub (??)

N

Norman Yang

Hi all:

I defined a type "PAD" in a VBA program and 7 element in it. Then
defined a variable as the "PAD" type. When I try to pass the variable
to a sub, the VB compiler reported that variable is needed instead of
an expressment.

Is there any issue could cause this problem? Any clue about this.

Thanks!
Norman
(e-mail address removed)
 
P

Perry

Kindy provide a snippet of yr code. Specifically, the type declaration and
the procedure heading
in which y're trying to pass a parameter.

If you don't want to share code, pls rephrase yr question.
-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
 
S

Shauna Kelly

Hi Norman

Try something like this:

Option Explicit

Public Type pad
iInteger As Integer
sString As String
docDoc As Word.Document
End Type


Public Sub Main()

Dim mypad As pad

With mypad
.iInteger = 12
.sString = "hello"
Set .docDoc = ActiveDocument
End With

TestUserType pad:=mypad

End Sub


Public Sub TestUserType(ByRef pad As pad)

With pad
MsgBox .sString
MsgBox .docDoc.Name
End With

End Sub


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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