Human_doing
Board Regular
- Joined
- Feb 16, 2011
- Messages
- 137
Hi all,
Can anyone please help with why the below VBA doesn't work? The idea is that when activated there is a dialogue box asking for an Excel file to be selected, when selected a new workbook is created, sheet 1 of the previously selected workbook is copied and pasted to sheet 1 of the new workbook.
When I run this, it does create a new workbook and the copied data is there to be pasted when I manually select 'paste' after running the macro, can anyone please help with why it doesn't paste automatically?
Sub TestIt()
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Select the file with raw data for the report")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=NewFN
End If
Cells.Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
End Sub
Can anyone please help with why the below VBA doesn't work? The idea is that when activated there is a dialogue box asking for an Excel file to be selected, when selected a new workbook is created, sheet 1 of the previously selected workbook is copied and pasted to sheet 1 of the new workbook.
When I run this, it does create a new workbook and the copied data is there to be pasted when I manually select 'paste' after running the macro, can anyone please help with why it doesn't paste automatically?
Sub TestIt()
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Select the file with raw data for the report")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=NewFN
End If
Cells.Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
End Sub