Share via

VBA variable declaration problems in excel 2011, mac

Anonymous
2012-02-24T21:05:41+00:00

Hello, 

I've tried quite hard to look for this problem elsewhere... and not finding an answer leads to think it's probably something i've done. Here goes;

I have a ecology modelling program written in VBA on a PC. I didn't write it, and I'm attempting to get it running on the mac.  It's quite big, but I thought it should work, but for some reason when it runs on the mac it wants all the variable declared. I'm no expert, but the tick box looks right in the editors settings.  I'm not sure there's anything to gain posting the code for this - every undeclared variable throws a runtime error. What have I missed?

It all runs fine on the PC.

I was also having trouble with the String() function... from another forum post, using VBA.String() seems to have fixed that. I only mention it in case it's a clue to something more fundamentally wrong with my installation.

Thanks for looking anyway, hope someone can shed some light on this.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-02-26T20:35:25+00:00

Thanks again Bob,

Yes - I thought that looked a bit odd. However, looking at the sheet of parameters I think C42 was intended by the author. Shouldn't throw an error though should it?

Sorry, you're right, the second one was me.

I tried this modified version on a PC and it failed too.

It's helpful to know that it looks ok... but I'm worried that .list should be .List? The editor is suppressing that caps L.  I think I'm going to try some .additem loops next and see where that gets me. Looking at the 2003 language reference (is this where i should be looking??) - .list should work, but something is up with it.

http://msdn.microsoft.com/en-us/library/aa195781(v=office.11).aspx

The original issue - declaration of variables - does seem to have been remedied by removing that missing reference though, so I guess we should call this thread case closed and do some fiddleing about and open up a new thread when i know enough to know the question I should be asking!

Thanks again for you help guys.

Was this answer helpful?

0 comments No comments

8 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-02-25T11:53:21+00:00

    Thanks for your reply. No, I don't think there are any OS references, at least I haven't found any yet... and i'm told it works on Excel 2004, so it isn't an active X issue. It's every variable that hasn't been declared with a dim statement.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-02-25T11:49:38+00:00

    Private Sub AgreeButton_Click()

    WelcomeForm.Hide

    With LandCoverChangeForm

    .LCCvegtype.Value = 0

    .LCCvegtype.BoundColumn = 0

    .LCCvegtype.ListIndex = 0

    .LCCDefaultInstantaneousLossOptions.Value = 0

    .LCCDefaultInstantaneousLossOptions.ListIndex = 0

    Worksheets("CASS model").Range("t14") = .LCCvegtype.Value + 1

    End With

    With LandUseChangeForm

    .LUCDefaultDisturbanceHarvest.Value = 0

    .LUCDefaultDisturbanceHarvest.ListIndex = 0

    End With

    UploadLCCDisturbanceParameters

    UploadLUCDisturbanceParameters

    With DisturbanceForm

    .DistDefaultDisturbance.ListIndex = 0

    .DistDefaultDisturbance.Value = 0

    UploadDisturbanceParameters

    End With

    CurrentDisturbance = 1

    CurrentLUCDisturbance = 1

    CurrentLCCDisturbence = 1

    LoadVegetationData

    End Sub

    Private Sub DisagreeButton_Click()

    'Windows("CASS.xls").Activate

    ActiveWorkbook.Close

    End Sub

    Private Sub DisclaimerLabel_Click()

    End Sub

    That's a reasonable request... I was hoping there would be an off-shelf 'known cure' for me. How naive!

    There' s quite a lot of it. Here's the first error I 'fixed', above.

    Notice the typo "CurrentLCCDisturbence = 1".

    On the PC, this just creates a new variable - the mac throws an error.

    Of course, having fixed that - I now find there are dozens of purposefully undeclared variables lurking in the module, all of which throw errors.

    Incidentally, 'ActiveWorkbook.Close' creates an error too, "Run-time error '1004': The specified dimension is not valid for the current chart type." but I'm ignoring that for now.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-02-24T23:43:44+00:00

    Not possible to even hint at the problem without seeing the code. Unl;ess you have a specific error or question., We can't provide much help.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-02-24T23:26:52+00:00

    Post it.

    It possible it using code that the Mac can't use such as Active-X.

    also any references using " / " Mac uses : or :: instead. (remember OSX is  Unix Based)

    There are 4 great people on the forums that know the in and outs of  Macros. I get the feeling they dream about them when they go to sleep. I am not one of those. I never used Macros because of the threat of virus from the day I installed Word 6.0.1a back in 1995  :-)

    Looking at  Macros to me is the equivalent to looking at Klingon.

    Was this answer helpful?

    0 comments No comments