Consulting

Results 1 to 10 of 10

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

  1. #1

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

    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

  2. #2
    please help me !!!

  3. #3
    VBAX Regular
    Joined
    Dec 2013
    Posts
    14
    Location
    I *think* you're going to need to get into AppleScript to get this working, I doubt you can do this directly in VBA

  4. #4
    so could you show me how to correct the problem

  5. #5
    VBAX Regular
    Joined
    Dec 2013
    Posts
    14
    Location
    Nope, I don't know AppleScript...

  6. #6
    anyone please help me

  7. #7
    up for helping

  8. #8
    VBAX Mentor tpoynton's Avatar
    Joined
    Feb 2005
    Location
    Clinton, MA
    Posts
    399
    Location
    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.

  9. #9
    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

  10. #10
    VBAX Mentor tpoynton's Avatar
    Joined
    Feb 2005
    Location
    Clinton, MA
    Posts
    399
    Location
    try this for starters
    Quote Originally Posted by lethanhtrung View Post
    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 )
    ----------------------------------
    [vba]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[/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •