+ Reply to Thread
Results 1 to 4 of 4

Delete sheets and create a new workbook in Shared Workbook.

Hybrid View

honger Delete sheets and create a... 06-02-2014, 10:57 AM
honger Re: Delete sheets and create... 06-02-2014, 11:47 AM
honger Re: Delete sheets and create... 06-02-2014, 12:20 PM
honger Re: Delete sheets and create... 06-02-2014, 01:35 PM
  1. #1
    Registered User
    Join Date
    12-07-2013
    Location
    NJ
    MS-Off Ver
    2010
    Posts
    91

    Delete sheets and create a new workbook in Shared Workbook.

    Hi All,

    I wrote a code in unshared workbook and it works fine. But when i make it shared i get Run-time error '1004' Delete method of worksheet class failed.

    The Deleting of worksheet only occurs once (when the new wb is created) so is there i can unshare and share it back when the process is complete?

    Private Sub CommandButton1_Click()
     
    Dim newWBK As Workbook
    
    'Grab Data From UserFrom
    MyProduct = UserForm1.ComboBox1.Value
    MyApplication = UserForm1.ComboBox2.Value
    MySCN = UserForm1.TextBox1.Value
    MyEvent = UserForm1.TextBox2.Value
    MyTemplate = UserForm1.ComboBox3.Value
     
    Unload UserForm1
    UserForm1.Hide
    
    Dim vFilename As Variant
    Dim vpath1 As Variant
    Dim vpath2 As Variant
    vpath1 = "\\tarcds01\eCTD_Submission\TRACKERS\" & MyProduct & "\" & MyApplication & "\"
    vpath2 = MyProduct & "-" & MyApplication & "-" & MySCN & "-" & MyEvent
    
    ActiveWorkbook.SaveCopyAs Filename:=vpath1 & vpath2 & ".xlsm"
    
    'name new WB
        Set newWBK = Workbooks.Open(vpath1 & vpath2 & ".xlsm")
    'Make the new workbook active
        newWBK.Activate
    
    'Select Template
    Application.DisplayAlerts = False
    If ComboBox3.Value = "Master" Then
        newWBK.Sheets(Sheet5.Name).Delete
        newWBK.Sheets(Sheet6.Name).Delete
        newWBK.Sheets(Sheet7.Name).Delete
        newWBK.Sheets(Sheet8.Name).Delete
        newWBK.Sheets(Sheet9.Name).Delete
        End If
    Application.DisplayAlerts = True
    
    Application.DisplayAlerts = False
    If ComboBox3.Value = "BLA Annual Report" Then
        newWBK.Sheets(Sheet1.Name).Delete
        newWBK.Sheets(Sheet6.Name).Delete
        newWBK.Sheets(Sheet7.Name).Delete
        newWBK.Sheets(Sheet8.Name).Delete
        End If
    Application.DisplayAlerts = True
    
    'etc
    'etc
    'Note - there are multiple selections to choose from ComboBox3 and deletes sheets according to it from this WB
    
    newWBK.Save
    newWBK.Activate
    
    'Close the template without saving
    ThisWorkbook.Close False
    
    
    End Sub

  2. #2
    Registered User
    Join Date
    12-07-2013
    Location
    NJ
    MS-Off Ver
    2010
    Posts
    91

    Re: Delete sheets and create a new workbook in Shared Workbook.

    So if i were to leave the source WB as unshared, and then share it when new WB is created, do i need to just turn on sharing when the newWBK is saved? i put the following code in but getting error again
    new code
    newWBK.SaveAs newWBK.FullName, xlaccess:=xlShared
    replaced
    newWBK.Save
    newWBK.Activate
    Compile error: Named argument not found

  3. #3
    Registered User
    Join Date
    12-07-2013
    Location
    NJ
    MS-Off Ver
    2010
    Posts
    91

    Re: Delete sheets and create a new workbook in Shared Workbook.

    i think im getting close. It is doing everything i ask for with the below code, however since the WB is already created it asks me to copy over the exisiting file. Is there anyway to just save without the prompt? i inserted the following code, but its asking to copy over the exisitng file.

    ActiveWorkbook.Save ActiveWorkbook.FullName, accessmode:=xlShared
    
    Application.DisplayAlerts = False

  4. #4
    Registered User
    Join Date
    12-07-2013
    Location
    NJ
    MS-Off Ver
    2010
    Posts
    91

    Re: Delete sheets and create a new workbook in Shared Workbook.

    stupid oversight on my part. ive solved it
    Application.DisplayAlerts = False
    ActiveWorkbook.Save ActiveWorkbook.FullName, accessmode:=xlShared
    Application.DisplayAlerts = True

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Delete Sheet on a Shared Workbook
    By johnjmcnaughton in forum Excel General
    Replies: 3
    Last Post: 10-30-2013, 05:31 PM
  2. remove ability to delete in a shared workbook
    By toclare84 in forum Excel General
    Replies: 0
    Last Post: 01-23-2012, 08:36 AM
  3. Automatically Copy sheets in one workbook to create sheets in a new workbook..
    By leebarratt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-13-2011, 03:14 AM
  4. Create multiple sheets in new workbook based on credentials in source workbook
    By Julesdude in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-07-2011, 10:31 AM
  5. Create a menu of sheets in a shared workbook
    By RichieRich in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-16-2005, 06:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1