macro to disconnect data connections when copying a sheet from master to standalone wrkbk

ansvk1

Board Regular
Joined
Oct 6, 2017
Messages
82
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi there,
I have a code for creating a separate worksheet for any active sheet out of a master workbook that has data connections in it. now i am looking for a way to insert macro code that can:
  1. make sure this new workbook being created is matching the original format
  2. disconnecting all the data connections and bringing only values for those connections

Here is my code:
Rich (BB code):
Sub Button1_Click()


    Dim ws As Worksheet
    Dim wbNew As Excel.Workbook, wbCurrent As Excel.Workbook
    Dim strFileName As String


    'Assign object variables
    Set wbCurrent = ActiveWorkbook
    Set ws = wbCurrent.ActiveSheet


    'Get desired file path from user
    strFileName = InputBox("Enter File Name: ", "Creating New File...")
    If strFileName <> "" Then
        
    'copy whole current sheet but with format intact & disconneting data connections, while bringing just their values over
        ws.Copy
        myFileName = wbCurrent.Path & "\" & strFileName & ".xlsx"
        ActiveWorkbook.SaveAs wbCurrent.Path & "\" & strFileName
    End If
End Sub

thanks for your help!
 
Ok thanks!
i will try it out Monday morning when i get to my PC and let you know how it went.
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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