+ Reply to Thread
Results 1 to 3 of 3

Open another workbook with command button

Hybrid View

  1. #1
    Registered User
    Join Date
    02-10-2018
    Location
    Aarhus
    MS-Off Ver
    Office 365
    Posts
    1

    Post Open another workbook with command button

    Hi,

    I would like to make a main page where you can choose between different pages in a data validation list. Something in the direction as shown in the picture.
    Once you have chosen the page you want to visit in the list, press the command button. Then another workbook must open, on the selected page and in a specific cell.

    Unavngivet.jpg

    How can I make it?

    Hopefully there is someone who can help me

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Open another workbook with command button

    Without a command button
    This assumes that it is the same cell in every sheet
    Amend the 3 constant values to match your file path, file name and the cell reference
    The change in the value of the cell A1 triggers file to open
    Test in attached file

    Code is in sheet module
    Private Sub Worksheet_Change(ByVal Target As Range)
    Const FilePath = "C:\TestArea\"                     'end with "\"
    Const FileName = "ThisIsYourFile.xlsx"     'incl extension
    Const CellRef = "F10"
    Dim sht As String, wb As Workbook
        
        If Not Intersect(Range("A1"), Target) Is Nothing Then
            If Target <> "SELECT" Then
                sht = Target.Value
                    'reset cell value
                        Application.EnableEvents = False
                            Target.Value = "SELECT"
                        Application.EnableEvents = True
                'open workbook, select corect sheet and cell
                    Set wb = Workbooks.Open(FilePath & FileName)
                    wb.Sheets(sht).Activate
                    ActiveSheet.Range(CellRef).Select
              End If
        End If
        
    End Sub
    Attached Files Attached Files
    Last edited by kev_; 02-10-2018 at 07:09 PM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Open another workbook with command button

    Using command button

    Does same as previous code, only this time behind command button
    Private Sub CommandButton1_Click()
        Const FilePath = "C:\TestArea\"                     'end with "\"
        Const FileName = "ThisIsYourFile.xlsx"     'incl extension
        Const CellRef = "F10"
        Dim sht As String, wb As Workbook
        
        sht = ActiveSheet.Range("A1").Value
        Set wb = Workbooks.Open(FilePath & FileName)
        wb.Sheets(sht).Activate
        ActiveSheet.Range(CellRef).Select
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Test for file open from Command Button on userform - not displaying open already message
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-02-2017, 09:45 AM
  2. Open/Save/Close Workbook via command button
    By nathan0519 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-31-2015, 11:24 PM
  3. Replies: 0
    Last Post: 06-10-2014, 10:44 PM
  4. [SOLVED] Command Button to open folder
    By Will_iam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2013, 06:18 AM
  5. [SOLVED] Using a command button to open a PDF
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-05-2013, 02:29 PM
  6. [SOLVED] Command Button to retireive open workbook names
    By Robotacha2010 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-25-2012, 08:49 AM
  7. [SOLVED] command button:Can i use a command button to open diffrrent sheets
    By Hellboy in forum Excel General
    Replies: 0
    Last Post: 11-03-2005, 11:00 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1