open work books

edwardfraser

Board Regular
Joined
Feb 28, 2013
Messages
65
Hi there is there a simple script I can use to open a work book?

This is crucial for me in the development of my macro

I am trying to build on my script so can use it to open workbooks even on a network envirmoment.

The current script I have is as follows:

Dim Myfile As String
Myfile = Application.GetOpenFilename()
Workbooks.open (Myfilename)



I dont think goes far enough.


I want to also have a error function built in for if the target file is open already or cant be found it the target location.

Thanks heaps
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I'll start you off. If you intend to reference your newly-opened workbook, you'll have to declare a suitable object to use to reference it. So for example:-

Code:
Dim Myfile As String
Dim MyWorkbook As Excel.Workbook
Dim MyWorksheet As Excel.Worksheet
'
 Myfile = Application.GetOpenFilename()
 Set MyWorkbook = Workbooks.Open(Myfile)
' 
 Set MyWorksheet = MyWorkbook.Sheets(1)
' 
'  now[COLOR=#008000] use MyWorksheet to access the data[/COLOR]
' 
 MsgBox "Cell A1 contains " & MyWorksheet.Range("A1")

BTW, you declared Myfile but used Myfilename in your code. That wouldn't have helped.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top