lethanhtrung4983
Thành viên mới

- Tham gia
- 21/6/15
- Bài viết
- 4
- Được thích
- 0
Chào các bạn, mình có viết một macro và nó chạy tốt trên windows nhưng không chạy được trên mac osx, các bạn giúp mình với
-------------------------------------------
Private Sub Workbook_Open()
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 "khong co ket noi internet"
Else
Dim vt As Workbook
Set vt = ThisWorkbook
On Error Resume Next
Workbooks.Open Filename:="path to file", 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
-------------------------------------------
Private Sub Workbook_Open()
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 "khong co ket noi internet"
Else
Dim vt As Workbook
Set vt = ThisWorkbook
On Error Resume Next
Workbooks.Open Filename:="path to file", 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