vb macro

  • Thread starter Thread starter bob
  • Start date Start date
B

bob

I have a vb macro running in an excel97 document that
works fine on an NT/2000 PC. However, when I run the same
macro from and XP Pro workstation I am getting errors and
they seem to be related to not having variables
dimensioned. What could be my problem?
 
Bob,

Are you specifying the variables in your code (such as):
Dim x as Long
Public y as String
Static a as Range

And is Option Explicit at the top of the Module?
 
No not all variables are dimensioned and Option Explicit
is not in the module. I didn't write the code, it was
written by someone else who no longer works here. What's
strange is that the same code works great on an NT machine
but not on XP.
For instance, in the following code the 'PIC' variable is
not dimensioned, however, it must be in order for the code
to function on an XP workstation but on the NT machine it
works fine. I am finding this situation all throughout
the code.

Private Sub Apply_Click()
If IsNumeric(RPM.Value) And IsNumeric(D.Value) And
IsNumeric(R.Value) And IsNumeric(L.Value) And IsNumeric
(A.Value) Then
If RPM.Value > 0 And D.Value > 0 And R.Value > 0
And L.Value > 0 And A.Value >= 0 Then
Tread.RPM = RPM.Value: Tread.Ra = D.Value:
Tread.Rf = R.Value: Tread.Rr = L.Value: Tread.FDC = A.Value
If I11cw.Visible = True Then Tread.ROT =
1: Tread.CONFIG = -1: PIC = "C:\1ICW.bmp"
If I11ccw.Visible = True Then Tread.ROT = -
1: Tread.CONFIG = -1: PIC = "C:\1ICCW.bmp"
If I14cw.Visible = True Then Tread.ROT =
1: Tread.CONFIG = 1: PIC = "C:\1IVCW.bmp"
If I14ccw.Visible = True Then Tread.ROT = -
1: Tread.CONFIG = 1: PIC = "C:\1IVCCW.bmp"
If I21cw.Visible = True Then Tread.ROT =
1: Tread.CONFIG = 1: PIC = "C:\2ICW.bmp"
If I21ccw.Visible = True Then Tread.ROT = -
1: Tread.CONFIG = 1: PIC = "C:\2ICCW.bmp"
If I22cw.Visible = True Then Tread.ROT =
1: Tread.CONFIG = -1: PIC = "C:\2IICW.bmp"
If I22ccw.Visible = True Then Tread.ROT = -
1: Tread.CONFIG = -1: PIC = "C:\2IICCW.bmp"
If I33cw.Visible = True Then Tread.ROT =
1: Tread.CONFIG = 1: PIC = "C:\3IIICW.bmp"
If I33ccw.Visible = True Then Tread.ROT = -
1: Tread.CONFIG = 1: PIC = "C:\3IIICCW.bmp"
If I34cw.Visible = True Then Tread.ROT =
1: Tread.CONFIG = -1: PIC = "C:\3IVCW.bmp"
If I34ccw.Visible = True Then Tread.ROT = -
1: Tread.CONFIG = -1: PIC = "C:\3IVCCW.bmp"
If I42cw.Visible = True Then Tread.ROT =
1: Tread.CONFIG = 1: PIC = "C:\4IICW.bmp"
If I42ccw.Visible = True Then Tread.ROT = -
1: Tread.CONFIG = 1: PIC = "C:\4IICCW.bmp"
If I43cw.Visible = True Then Tread.ROT =
1: Tread.CONFIG = -1: PIC = "C:\4IIICW.bmp"
If I43ccw.Visible = True Then Tread.ROT = -
1: Tread.CONFIG = -1: PIC = "C:\4IIICCW.bmp"
Worksheets("Export Sheet").Cells(11, 2).Value
= PP.Value + "-" + RP.Value + "-" + CR.Value
Worksheets("Export Sheet").Cells(11, 4).Value
= RPM.Value
Worksheets("Export Sheet").Cells(12, 2).Value
= D.Value
Worksheets("Export Sheet").Cells(13, 2).Value
= R.Value
Worksheets("Export Sheet").Cells(12, 4).Value
= L.Value
Worksheets("Export Sheet").Cells(13, 4).Value
= A.Value
Worksheets("EXPORT SHEET").Activate
Range("G10").Select
Sheet11.Pictures.Insert(PIC).Select
GIF.Hide
Sheet1.LabNumberSegs.Enabled = True:
Sheet1.LabNumSeg.Enabled = True: Sheet1.NumSegSp.Enabled =
True
Sheet1.Done.Enabled = True
Else: GWF.Show
End If
Else: GWF.Show
End If
End Sub
 
Can't speak for XP (it's an unknown for me). But you'll need to find each
error and figure out how to fix it (there are some differences between XP
and 97).

If you add Option Explict - Excel will help pinpoint some (if not all) of
the
problem areas. Use Debug > Compile to get to them.

You may have to step through your code using F8 to see where the
problems are.

You can also use the Watch window to see the value and how Excel
defines the variable types providing you Dim each variable without setting
its type (this way Excel sees them as Variant and then set them). When
you're finished go back and define the variables.
 
Back
Top