ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User-defined type not defined (https://www.excelbanter.com/excel-programming/410864-user-defined-type-not-defined.html)

shapper

User-defined type not defined
 
Hello,

I have a Worksheet with 36 images all them having a name.

I also have a button that run clicked runs the Macro "Play". And I
have the following code:

Private Sub Workbook_Open()

Option Explicit

Type TpJogo
fig(1 To 6, 1 To 6) As String
LastRow As Integer
LastCol As Integer
Score As Integer
End Type ' TpJogo

Public jogo As TpJogo

Sub Play()

With jogo
.fig = ("gar2")
.LastRow = 8
.LastCol = 7
.Score = 0
End With

Coloca_Pos(jogo, 6, 6) = 1

End Sub

Sub Coloca_Pos(ByRef jogo As TpJogo, ByVal r As Integer, ByVal c As
Integer)

Dim hc As Single, hf As Single, wc As Single, wf As Single
Dim nf As String
On Error GoTo fim
With Range("tabuleiro")
hc = .Cells(r, c).Height
wc = .Cells(r, c).Width
nf = jogo.fig(r, c)
hf = ActiveSheet.Shapes(nf).Height
wf = ActiveSheet.Shapes(nf).Width
ActiveSheet.Shapes(nf).Top = .Cells(r, c).Top + (hc - hf) / 2
ActiveSheet.Shapes(nf).Left = .Cells(r, c).Left + (wc - wf) / 2
End With
fim:

End Sub ' Coloca_Pos

End Sub

When I click the I get the following error:
User-defined type not defined.

What am I doing wrong?

Thanks,
Miguel

Jim Thomlinson

User-defined type not defined
 
You have a bunch of problems...

What is this line for.
Private Sub Workbook_Open()

You defined fig as an array so you can not just assign to it
..fig = ("gar2")

Coloca_Pos is a sub so the = sign makes no sense
Coloca_Pos(jogo, 6, 6) = 1

You have 2 end subs in one procedure.
End Sub ' Coloca_Pos
End Sub

Probably not a problem but you defined
LastRow As Integer
but integer maxed out at 32k. There are 65k rows.
--
HTH...

Jim Thomlinson


"shapper" wrote:

Hello,

I have a Worksheet with 36 images all them having a name.

I also have a button that run clicked runs the Macro "Play". And I
have the following code:

Private Sub Workbook_Open()

Option Explicit

Type TpJogo
fig(1 To 6, 1 To 6) As String
LastRow As Integer
LastCol As Integer
Score As Integer
End Type ' TpJogo

Public jogo As TpJogo

Sub Play()

With jogo
.fig = ("gar2")
.LastRow = 8
.LastCol = 7
.Score = 0
End With

Coloca_Pos(jogo, 6, 6) = 1

End Sub

Sub Coloca_Pos(ByRef jogo As TpJogo, ByVal r As Integer, ByVal c As
Integer)

Dim hc As Single, hf As Single, wc As Single, wf As Single
Dim nf As String
On Error GoTo fim
With Range("tabuleiro")
hc = .Cells(r, c).Height
wc = .Cells(r, c).Width
nf = jogo.fig(r, c)
hf = ActiveSheet.Shapes(nf).Height
wf = ActiveSheet.Shapes(nf).Width
ActiveSheet.Shapes(nf).Top = .Cells(r, c).Top + (hc - hf) / 2
ActiveSheet.Shapes(nf).Left = .Cells(r, c).Left + (wc - wf) / 2
End With
fim:

End Sub ' Coloca_Pos

End Sub

When I click the I get the following error:
User-defined type not defined.

What am I doing wrong?

Thanks,
Miguel



All times are GMT +1. The time now is 06:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com