Hi,
I have a macro that imports information from closed wordbooks that are stored in a subfolder where the main file is. That folder may vary depending on the user.
I have got a macro to do so. It works ok on windows. However, I have to port it to Mac now. And part of the code does not work:
I am assuming that it fails at getting the path.
I have to say my VBA knowledge is very limited and I have managed to build a few macros following examples from here and there.
Can you please helping me on making this work on Excel 2011 for Mac?
Is it possible have code that detects if the file is being opened on Windows or Mac and it chooses the right code?
The macro is triggered when the the file is opened by the following code:
Thank you,
Luis
I have a macro that imports information from closed wordbooks that are stored in a subfolder where the main file is. That folder may vary depending on the user.
I have got a macro to do so. It works ok on windows. However, I have to port it to Mac now. And part of the code does not work:
Code:
Sub GetDataFromClosedTimesheets()
On Error Resume Next
Dim wb As Workbook
Msg = "Would you like to import the latest data from the timesheets?"
Ans = MsgBox(Msg, vbYesNo + vbQuestion)
If Ans = vbNo Then Exit Sub
If Ans = vbYes Then Application.ScreenUpdating = False ' turn off the screen updating
Set wb = Workbooks.Open(ActiveWorkbook.Path & "\Market1\Supplier1.xlsx", True, True)
' open the source workbook, read only
With ThisWorkbook.Worksheets("Supplier1")
' read data from the source workbook
.Range("e6:bd17").Value = wb.Worksheets("SUMMARY").Range("f28:be39").Value
.Range("e23:p34").Value = wb.Worksheets("SUMMARY").Range("f45:q56").Value
.Range("e40:h51").Value = wb.Worksheets("SUMMARY").Range("f62:i73").Value
End With
wb.Close False ' close the source workbook without saving any changes
Set wb = Nothing ' free memory
' next language
Set wb = Workbooks.Open(ActiveWorkbook.Path & "\Market1\Supplier2.xlsx", True, True)
' open the source workbook, read only
With ThisWorkbook.Worksheets("Supplier2")
' read data from the source workbook
.Range("e6:bd17").Value = wb.Worksheets("SUMMARY").Range("f28:be39").Value
.Range("e23:p34").Value = wb.Worksheets("SUMMARY").Range("f45:q56").Value
.Range("e40:h51").Value = wb.Worksheets("SUMMARY").Range("f62:i73").Value
End With
wb.Close False ' close the source workbook without saving any changes
Set wb = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
MsgBox "Timesheet information has been updated", vbInformation
End Sub
Private Function GetData(Path, File, Sheet, Address)
Dim Data$
Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _
Range(Address).Range("A1").Address(, , xlR1C1)
GetData = ExecuteExcel4Macro(Data)
End Function
I am assuming that it fails at getting the path.
I have to say my VBA knowledge is very limited and I have managed to build a few macros following examples from here and there.
Can you please helping me on making this work on Excel 2011 for Mac?
Is it possible have code that detects if the file is being opened on Windows or Mac and it chooses the right code?
The macro is triggered when the the file is opened by the following code:
Code:
Private Sub Workbook_Open()
Run "GetDataFromClosedTimesheets"
End Sub
Thank you,
Luis