Need help to convert windows excel vba code to run on mac osx

lethanhtrung

New Member
Joined
Jun 21, 2015
Messages
6
i'm a windows users and have no Mac osx experience, so please help me , thank you verymuch
( The below code works well on windows x64 excel 2010 but cannot run on Mac osx excel 2011 )
----------------------------------
Private Sub Workbook_Open()


' check internet connection


Dim oPing As Object, oRetStatus As Object, i As Byte


Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '8.8.8.8'")


For Each oRetStatus In oPing
If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
i = 0
Else
i = 1
End If
Next


If i = 0 Then
MsgBox "No internet connection"
Else


Dim vt As Workbook
Set vt = ThisWorkbook


' open file on ftp server and do something


On Error Resume Next
Workbooks.Open Filename:="path on ftp server", password:="111"


If Error.Number = 0 Then


If Workbooks("abc.xlsx").Sheets(1).Cells(1, "Z").Value > vt.Sheets(1).Cells(1, "Z").Value Then


If MsgBox("message", vbOKCancel, "name") = vbOK Then


vt.Sheets(1).Cells(1, "Z").Value = Workbooks("abc.xlsx").Sheets(1).Cells(1, "Z").Value
vt.Worksheets(1).Unprotect ("111")
Workbooks("abc.xlsx").Sheets(1).Rows("1:200").Copy
vt.Sheets(1).Rows.Range("1:200").PasteSpecial Paste:=xlPasteAll
vt.Worksheets(1).Protect ("111")
Application.CutCopyMode = False
Workbooks("abc.xlsx").Close
vt.Sheets(1).Cells(1, 1).Select
vt.Save
Else
Workbooks("abc.xlsx").Close
End If


End If
Else
Err.Clear


End If
Workbooks("abc.xlsx").Close


End If


End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I think if you want to perform a Ping operation on a Mac you'll need to do get the value via an Applescript and turn that value over to your VBA code. Mac OS X is really a front end for UNIX, which you can access programmatically.

See this article for getting AppleScript to perform UNIX operarations:
New Unix Applescript commands - Mac OS X Hints

See this article for getting a Ping in UNIX
Linux and Unix ping command help and examples

See this page for instructions on how to get variables from AppleScript into VBA
Can I pass parameters to a Word 2011 macro, from applescript? - Microsoft Community
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top