Copy sheet to chosen workbook

femma

Board Regular
Joined
Jul 13, 2016
Messages
156
Hi forum!

Trying to copy the active sheet to the workbook chosen by the user - but having trouble with how to define the new workbook.
Code:
 Sub ssss()
 Dim myfile As Variant
 


    Application.DisplayAlerts = False
    Application.CopyObjectsWithCells = False
    ActiveSheet.Copy
     
    With ActiveSheet.UsedRange
        .Value = .Value
         
    End With
myfile = Application.GetOpenFilename

    If myfile <> False Then
    Workbooks.Open Filename:=myfile
   
   
'this part does not work -should copy the chosen file to the workbook chosen by the user
    End If
    
    Application.CopyObjectsWithCells = True
    Application.DisplayAlerts = True
    
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Code:
 [color=darkblue]Sub[/color] ssss()
    
    [color=darkblue]Dim[/color] myfile [color=darkblue]As[/color] [color=darkblue]Variant[/color], ws [color=darkblue]As[/color] Worksheet
    
    myfile = Application.GetOpenFilename
    
    [color=darkblue]If[/color] myfile <> [color=darkblue]False[/color] [color=darkblue]Then[/color]
        
        Application.DisplayAlerts = [color=darkblue]False[/color]
        Application.CopyObjectsWithCells = [color=darkblue]False[/color]
        
        ActiveSheet.Copy After:=Sheets(Sheets.Count)
        [color=darkblue]Set[/color] ws = ActiveSheet
        
        [color=darkblue]With[/color] ws.UsedRange
            .Value = .Value
        [color=darkblue]End[/color] [color=darkblue]With[/color]
        
        Workbooks.Open Filename:=myfile
        
        ws.Copy After:=Sheets(Sheets.Count)
        
        ws.Delete
        
        Application.CopyObjectsWithCells = [color=darkblue]True[/color]
        Application.DisplayAlerts = [color=darkblue]True[/color]
        
    [color=darkblue]End[/color] [color=darkblue]If[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top