Address of workbook in a macro
Doug is right...
Sub test()
Const WBname = "MyWorkbook.xls"
Const WSname = "records"
Dim WB As Workbook
Dim WS As Worksheet
On Error Resume Next
Set WB = Workbooks(WBname)
on error goto 0
If WB Is Nothing Then
MsgBox "Workbook " & WBname & vbLf & "is not opened"
Exit Sub
End If
on error resume next
Set WS = WB.Worksheets(WSname).Select
on error goto 0
If WB Is Nothing Then
MsgBox "Workbook " & WBname & vbLf & _
"has no sheet " & WSname
Exit Sub
End If
WB.Select
End Sub
"frendabrenda1" a écrit dans le
message de ...
I have an Excel workbook on a netwrok drive that has macros which create
record numbers and copy each record and its data to a specific worksheet
in
the file. I am having problems with users copying the file or creating
shortcuts and ending up with duplicate copies of the file which pretty
much
destoys the the validity of the records.
I was thinking there might be a way in the macro, rather than say
sheets("records").select I could provide the address of the correct
file
like sheets(G:\\Workbook "records").select If the user were not in the
correct network drive version of the workbook, then the macro could not
find
the sheet and give an error.
Is there a way to make this work, or any other ideas as to how to stop
copying of the file in any way or set up a file that can be distributed to
everyone that will only open the right file.
Any ideas would be gretly appreciate. Thank you so much!
brenda
|