Hello,
I am using the following code to transfer battery testing data from .csv files into a .xlsm file.
It gets what I need done but, if I select "Cancel" from the input file box it creates a Run-time error '1004': 'False.xlsx' could not be found.........
What do I need to add to my code to stop this?
Sub CommandButton1_Click()
Dim batteryBook As Workbook
Dim filter As String
Dim caption As String
Dim batteryFilename As String
Dim batteryWorkbook As Workbook
Dim targetWorkbook As Workbook
Set targetWorkbook = Application.ActiveWorkbook
filter = "Text files (*.csv),*.csv"
caption = "Please Select an input file "
batteryFilename = Application.GetOpenFilename(filter, , caption)
Set batteryWorkbook = Application.Workbooks.Open(batteryFilename)
Dim targetSheet As Worksheet
Set targetSheet = targetWorkbook.Worksheets(1)
Dim sourceSheet As Worksheet
Set sourceSheet = batteryWorkbook.Worksheets(1)
targetSheet.Range("A1").Value = sourceSheet.Range("B1").Value 'Will be adding more ranges..
batteryWorkbook.Close
End Sub
Bookmarks