ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open specific sheet depending on cell contents (https://www.excelbanter.com/excel-programming/360343-open-specific-sheet-depending-cell-contents.html)

monkey harry

Open specific sheet depending on cell contents
 
Hi,

I'm fairly new to VB and need to create a macro which will open another
workbook and more specifically a sheet within it depending on its
contents.

I'll try to be a bit clearer. Say cell "A1" contained the name of the
sheet in another workbook, can I get a macro to read the contents of
"A1" and open that specific sheet?

As I said I'm fairly new to this, so the actual code to do it would
excellent.

Thanks


Don Guillett

Open specific sheet depending on cell contents
 
The macro recorder is your friend. I just recorded this and then modified.

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 5/2/2006 by Don Guillett
'

'
'Workbooks.Open Filename:="C:\yourfolder\yourfilename.xls"
Workbooks.Open Filename:="C:\yourfolder\" & Range("a1") & ".xls"
End Sub


--
Don Guillett
SalesAid Software

"monkey harry" wrote in message
oups.com...
Hi,

I'm fairly new to VB and need to create a macro which will open another
workbook and more specifically a sheet within it depending on its
contents.

I'll try to be a bit clearer. Say cell "A1" contained the name of the
sheet in another workbook, can I get a macro to read the contents of
"A1" and open that specific sheet?

As I said I'm fairly new to this, so the actual code to do it would
excellent.

Thanks




Ivan Raiminius

Open specific sheet depending on cell contents
 
Hi,

supposing that cell A1 contains path and filename (like "c:\test.xls").
you can use this code

sub OpenFile()
workbooks.open(range("a1").value)
end sub

To open the file "test.xls"
This is just basic code without error trapping.

Regards,
Ivan


monkey harry

Open specific sheet depending on cell contents
 
Thanks

That's helped a lot!!!



All times are GMT +1. The time now is 02:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com