This code copies and pastes the worksheet I'm looking at: to selected excel file (include macro run button)
I wanted the macro to work on the pasted worksheet,So I put this variable in the code.
But ThisWorkbook is refers to the original file from which the macro was created.
And I found it. Module was not pasted.
How can I fix it?
I've read how to copy and paste myself,I want it to work automatically.
[/CODE]
VBA Code:
Set ww = ThisWorkbook.ActiveSheet
Set closedBook = Workbooks.Open(ReturnStr)
ww.Copy After:=closedBook.Sheets(Sheets.Count)
closedBook.Close SaveChanges:=True
I wanted the macro to work on the pasted worksheet,So I put this variable in the code.
But ThisWorkbook is refers to the original file from which the macro was created.
And I found it. Module was not pasted.
How can I fix it?
I've read how to copy and paste myself,I want it to work automatically.
VBA Code:
Sub worksheet_export()
Dim FDG As FileDialog
Dim Selected As Integer: Dim i As Integer
Dim ReturnStr As String: Dim tempStr As Variant
'SelectAgain:
Set FDG = Application.FileDialog(msoFileDialogFilePicker)
With FDG
.Title = "select file"
.Filters.Add "excel file", "*.xls,*.xlsx;*.xlsm;*.xlsb"
.InitialView = msoFileDialogViewList
.InitialFileName = "C:\Users\Admin\Google drive\Myfiles"
.AllowMultiSelect = False
Selected = .Show
If Selected = 0 Then
MsgBox "cancel"
'GoTo SelectAgain:
ElseIf Selected = -1 Then
ReturnStr = .SelectedItems(1)
Application.ScreenUpdating = False
Set ww = ThisWorkbook.ActiveSheet
Set closedBook = Workbooks.Open(ReturnStr)
ww.Copy After:=closedBook.Sheets(Sheets.Count)
closedBook.Close SaveChanges:=True
End If
End With
End Sub[CODE=vba]