Results 1 to 3 of 3

Thread: [RESOLVED] Open Worksheet from other book problem

  1. #1

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Resolved [RESOLVED] Open Worksheet from other book problem

    Hey all,

    On some occasions, I'm getting a warning message when opening a worksheet (found in another workbook) into my current workbook... The open still works fine, I'm just bothered by two warning messages that pop up.. and I can't figure out how to get rid of them.

    the warning message reads: A formula or sheet you want to move or copy contains the name 'Leach', which already exists on the destination worksheet. Do you want to use this version of the name?
    To use the name as defined in the destination sheet, click Yes.
    To rename the range referred to in the formula or worksheet, click No, and enter a new name in the Name Conflict dialog box.

    I don't ever remember naming a range in the saved sheet... Is there a way to check if I have any named ranges on a certain sheet? Or is there some code that can simply bypass this warning message? My code to open the sheet is as follows: Thanks much!

    vb Code:
    1. Application.DisplayAlerts = False
    2. Dim sfilename As String
    3. 'Show the open dialog and pass the selected _
    4. 'file name To the String variable "sFileName"
    5. sfilename = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls", Title:=vNum)
    6. 'They have cancelled.
    7. If sfilename = "False" Then Exit Sub
    8. Dim temp As String
    9. temp = spliceFileNameEnd2(sfilename)
    10. For Each shtnext In Sheets
    11.     If shtnext.Name = "nindex" Then 'Search/Delete charts w/ same name
    12.         Application.DisplayAlerts = False 'No delete prompt
    13.         Sheets("nindex").Delete
    14.         Application.DisplayAlerts = True
    15.     End If
    16. Next shtnext
    17. Workbooks.Open FileName:=sfilename
    18. Dim found As Boolean
    19. found = False
    20. For Each shtnext In Sheets
    21.     If shtnext.Name = "nindex" Then
    22.         found = True
    23.         Exit For
    24.     End If
    25. Next shtnext
    26. If found = False Then
    27.     Workbooks(temp).Close SaveChanges:=False
    28.     MsgBox ("No N-Index File was found in that file.")
    29.     Sheets.Add
    30.     ActiveSheet.Name = "nindex"
    31.     Exit Sub
    32. End If
    33. Sheets("nindex").Copy After:=Workbooks("NLEAPGIS10.xls").Sheets(ThisWorkbook.Sheets.Count)
    34. Workbooks(temp).Close SaveChanges:=False
    35.  
    36. Application.DisplayAlerts = True

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Open Worksheet from other book problem

    to bypass the warning you can make application.displayalerts = false, but this could cause othe issues
    to check for names in a workbook, try like this
    vb Code:
    1. Dim n As Name
    2. For Each n In Workbooks("test.xls").Names
    3. Debug.Print n.Name
    4. Next
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: Open Worksheet from other book problem

    Ah .. I didn't notice that I actually turned DisplayAlerts back on halfway through my code... thanks for the help westconn

Posting Permissions

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



Click Here to Expand Forum to Full Width