-
OK, I'll make it 4 of us using VBA on Mac! Looks like we need some activity around here, so I have a few to add to the list when I remember them. Right now I'm converting Excel VBA code from Office 2000 to Office X on my new machine and hitting plenty of problems. (Yeah, I'm too cheap to get Office 2004 yet).
The LoadPicture() method above hits me hard because I use it to update images in UserForms. Haven't found any useful workaround yet although I've read that it's been fixed in Office 2004 SP1. Right now I have to use conditional complilation to avoid compiler errors:
[VBA]#If Not Mac Then
UserForm.Picture = LoadPicture(picturename)
#End If[/VBA]
Next up... the InStrRev() function is not recognized and gives a compiler error. For this one I just created a new function to handle it under both Mac and Win:
[vba]Function RevSearch(ByVal string1 As String, ByVal string2 As String) As Integer
RevSearch = 0
Do While InStr(string1, string2)
RevSearch = RevSearch + InStr(string1, string2)
string1 = Right(string1, Len(string1) - InStr(string1, string2))
Loop
End Function
[/vba]
There are probably more elegant solutions, but I have a lot of ground to cover...
Another one: Application.GetOpenFileName() always seems to fail for selecting multiple files. Right now I'm using a very cludgy workaround that goes like this:
i) identify a directory using Application.GetOpenFileName() in single file mode.
ii) use this directory in a Application.FileFind search. This has to be done with conditional compilation as FileFind will cause a compilation error on Windows.
iii) list the FoundFiles in a ListBox and allow the user to select files from this list.
(BTW, I'm using this because I already have some code in there to allow the user to match filenames with comments stored in the spreadsheet before opening the files, so this was just reusing that code.)
Pasting arrays into worksheets. This one's a little random.
[vba]Dim MyData() as Variant, n as Integer
ReDim MyData(1 to lengthoffile, 1 to 1)
...
Do While blah-blah
Input #1, MyData(n, 1)
n = n + 1
Loop
Sheets("My Sheet").Cells(1, 1).Resize(UBound(MyData, 1), 1) = MyData[/vba]
...often fails with a Type Mismatch where file #1 just contains numeric data. It seems that Mac VBA is not as smart as WIN VBA in determining types for Variant. The fix here was to change the Input to:
[vba]Input #1, TempData
MyData(n, 1) = Val(TempData)[/vba]
This forces VBA to recognize the Variant array as numeric.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules