Open another workbook with a button click

  • Thread starter Thread starter celia
  • Start date Start date
C

celia

Hi,

I have 2 situations:

1. I have add 2 buttons (button A & button B) in my workbook calle
Project.xls, button A will open A.xls(sheet1) while button B wil
open-up B.xls (sheet2).


2. I have add 2 buttons (button A & button B) in my workbook calle
Project.xls, button A will open sheet "A"while button B will open-u
sheet "B" at the same workbook (Project.xls).

So, my question is how to do it ? how to write the respective codes
for the 2 situations?

Please help. Thanks.

Thankyou,
celi
 
Celia,

Code

Option Explicit
Public Const MyDir = "C:\TEMP\"
Public OpenFile As String
Sub OpenFileA()
OpenFile = "A.xls"
Workbooks.Open (MyDir & OpenFile)
End Sub
Sub OpenFileB()
OpenFile = "B.xls"
Workbooks.Open (MyDir & OpenFile)
End Sub
Sub OpenSheetA()
Worksheets("A").Activate
End Sub
Sub OPenSheetB()
Worksheets("B").Activate
End Sub

Use View-Toolbars-Forms to create button and attach respective macro t
it.

You should improve first two so that does not open file when alread
open.

Hope this helps...
 
Hi Celia,

Assuming A.xls and B.xls are files in directory c:\mydocuments
and "A" and "B" are then names of sheets in your workbook, then tr
copying these 4 macros into your visual basic editor (Alt+F11), the
adding 4 buttons, specifying each using one of the 4 macros:

Sub open_A()
Workbooks.Open Filename:="C:\mydocuments\A.xls"
End Sub

Sub open_B()
Workbooks.Open Filename:="C:\mydocuments\B.xls"
End Sub

Sub Goto_sheetA()
Sheets("A").Select
End Sub

Sub Goto_sheetB()
Sheets("B").Select
End Su
 
Hi guys,

Thanks for the help.

I will try the code now, hope there are no problem with it.

thanks,
celi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top