Results 1 to 5 of 5

Thread: Naming a new WorkBook

  1. #1
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    14

    Naming a new WorkBook

    Below is the code I use to add a new workbook - but How can I assign a name to the new workbook - If I try to use the .Name property - I am told readOnly. Any help is appreciated.

    Code:
    Dim NewBookX As Workbook
    Set NewBookX = Workbooks.Add
    xl2007 - Windows 7
    xl hates the 255 number

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi,

    Would this work ?

    Code:
    Dim NewBookX As Workbook
    Set NewBookX = Workbooks.Add
    
    If NewBookX.ReadOnly Then
        NewBookX.ChangeFileAccess Mode:=xlReadWrite
        NewBookX.Name = "NewName"
    End If

  3. #3
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    14
    ahhh - great - thanks
    xl2007 - Windows 7
    xl hates the 255 number

  4. #4
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Try this....

    Code:
        Dim wbkNew As Workbook
        Workbooks.Add(xlWorksheet).SaveAs Filename:="NewName", FileFormat:=&H34 '33 = XLSX, 34 = XLSM
        Set wbkNew = Workbooks("NewName.xlsm")
        With wbkNew
            .ChangeFileAccess xlReadOnly
            Kill .FullName
        End With
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  5. #5
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    14
    Will do - the other one did not like a full compile - thanks
    xl2007 - Windows 7
    xl hates the 255 number

Similar Threads

  1. Replies: 9
    Last Post: 09-09-2011, 02:30 AM
  2. Replies: 0
    Last Post: 09-06-2011, 01:31 AM

Posting Permissions

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