Hi, I'm experiencing problems with a globally declared Workbook: I seem to be able to extract data from it but every time I try to change a value in this workbook, the Function suddenly Exits without any error message. Any help would be greatly appreciated!!!
All my code is in a Module. I declare my variable at the top of the module with:
Public wbDataFile As Workbook
Then there is a Sub which sets the variable as follows:
Set wbDataFile = Workbooks.Open(strFullImportPath)
Now, the workbook in wbDataFile is completely empty (except a few strings for testing purposes. ThisWorkbook however is filled with cells out of which many invoke a function. This function should change cells in wbDataFile.Sheets(1). Now, if I just try to read data from wbDataFile it works flawless, e.g.
Public Function x (...)
With wbDataFile.Sheets(1)
MsgBox "Test: " & .Cells(1,1).Value
End With
End Function
Runs totally fine. However, as soon as I try to manipulate data, the function does stop executing suddenly without any error message.
Public Function x (...)
With wbDataFile.Sheets(1)
.Cells(1,1).Value = "Teststring"
MsgBox "Hello World"
End With
End Function
In other words: neither gets 1,1 filled with "Teststring" nor does a MessageBox appear. When I try debug-mode, the function simply terminates in the line trying to change Cell 1,1.
Other things I have tried is using Range instead of Cells and using a global Worksheet instead of a Workbook. Same result.
Any suggestions?
Thanks a lot in advance!
All my code is in a Module. I declare my variable at the top of the module with:
Public wbDataFile As Workbook
Then there is a Sub which sets the variable as follows:
Set wbDataFile = Workbooks.Open(strFullImportPath)
Now, the workbook in wbDataFile is completely empty (except a few strings for testing purposes. ThisWorkbook however is filled with cells out of which many invoke a function. This function should change cells in wbDataFile.Sheets(1). Now, if I just try to read data from wbDataFile it works flawless, e.g.
Public Function x (...)
With wbDataFile.Sheets(1)
MsgBox "Test: " & .Cells(1,1).Value
End With
End Function
Runs totally fine. However, as soon as I try to manipulate data, the function does stop executing suddenly without any error message.
Public Function x (...)
With wbDataFile.Sheets(1)
.Cells(1,1).Value = "Teststring"
MsgBox "Hello World"
End With
End Function
In other words: neither gets 1,1 filled with "Teststring" nor does a MessageBox appear. When I try debug-mode, the function simply terminates in the line trying to change Cell 1,1.
Other things I have tried is using Range instead of Cells and using a global Worksheet instead of a Workbook. Same result.
Any suggestions?
Thanks a lot in advance!