|
-
Jan 16th, 2008, 01:32 PM
#1
Thread Starter
Hyperactive Member
[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:
Application.DisplayAlerts = False
Dim sfilename As String
'Show the open dialog and pass the selected _
'file name To the String variable "sFileName"
sfilename = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls", Title:=vNum)
'They have cancelled.
If sfilename = "False" Then Exit Sub
Dim temp As String
temp = spliceFileNameEnd2(sfilename)
For Each shtnext In Sheets
If shtnext.Name = "nindex" Then 'Search/Delete charts w/ same name
Application.DisplayAlerts = False 'No delete prompt
Sheets("nindex").Delete
Application.DisplayAlerts = True
End If
Next shtnext
Workbooks.Open FileName:=sfilename
Dim found As Boolean
found = False
For Each shtnext In Sheets
If shtnext.Name = "nindex" Then
found = True
Exit For
End If
Next shtnext
If found = False Then
Workbooks(temp).Close SaveChanges:=False
MsgBox ("No N-Index File was found in that file.")
Sheets.Add
ActiveSheet.Name = "nindex"
Exit Sub
End If
Sheets("nindex").Copy After:=Workbooks("NLEAPGIS10.xls").Sheets(ThisWorkbook.Sheets.Count)
Workbooks(temp).Close SaveChanges:=False
Application.DisplayAlerts = True
-
Jan 16th, 2008, 03:29 PM
#2
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:
Dim n As Name For Each n In Workbooks("test.xls").Names Debug.Print n.Name 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
-
Jan 18th, 2008, 12:35 PM
#3
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|