PDA

View Full Version : Need help to convert windows excel vba code to run on mac osx



lethanhtrung
06-21-2015, 03:04 AM
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 but cannot run on Mac osx )

Private Sub Workbook_Open()
' check internet connection
Dim oPing As Object, oRetStatus As Object, i As Byte
Dim vt As Workbook
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
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

lethanhtrung
06-21-2015, 11:21 PM
please help me !!!

Kyle234
06-22-2015, 01:50 AM
I *think* you're going to need to get into AppleScript to get this working, I doubt you can do this directly in VBA

lethanhtrung
06-22-2015, 02:44 AM
so could you show me how to correct the problem :)

Kyle234
06-22-2015, 03:45 AM
Nope, I don't know AppleScript...

lethanhtrung
06-22-2015, 09:04 AM
anyone please help me

lethanhtrung
06-22-2015, 07:40 PM
up for helping

tpoynton
06-23-2015, 06:15 AM
see http://www.rondebruin.nl/mac.htm for some helpful information.

I am not the expert others around here are, but the two things I see are the internet connection check (definitely will not work) and maybe the ftp server save. I would comment out the internet check and work on getting the file from ftp server.

lethanhtrung
06-24-2015, 02:09 AM
yes, you are right, but i don't know how to fix the code to work on Mac, i've already see that link but have no information about my problem :(

tpoynton
06-24-2015, 06:13 AM
try this for starters

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 but cannot run on Mac osx )
----------------------------------
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