Solved

VBA to open workbook to specific tab

Posted on 2014-10-23
6
195 Views
Last Modified: 2014-10-24
Hi Experts,

Hoping that you can help with two issues that I am having with the vba below.   First issues is that I can't get the Application.AskToUpdateLinks to work,  I've place this on different lines and the alert still comes up.   The second is that once the file is open I would like it to open and display the Store Summary tab.  Currently it is opening to the last saved tab.

Sub ActualOpen()


    Dim wb As Workbook
    Dim fso As FileSystemObject
    Dim myFolder As Folder
    Dim myFile As File
    Dim newestFile As File
    Dim ws As Worksheet
    
    Set fso = New FileSystemObject
    
    '--------------------------------------------------------------------------------
    'For test purposes, I am using the "My Documents" folder... this needs to change
    ' To use whatever folder you need
    '--------------------------------------------------------------------------------
    
    Set myFolder = fso.GetFolder("\\SSFilePrint\GROUPSHARE\Store Planning\LSP Shared\International\Finance\VSBA & ROW")
    '\\SSFilePrint\GROUPSHARE\Store Planning\Projects\International\Store Schedules\JDE Store report
    

    
    Application.ScreenUpdating = False
    Application.AskToUpdateLinks = False
    Application.Calculation = xlCalculationManual
    
    For Each myFile In myFolder.Files
        Select Case UCase(fso.GetExtensionName(myFile.Path))
            Case "XLS", "XLSM", "XLSB", "XLSX":
        
                If newestFile Is Nothing Then
                    Set newestFile = myFile
                ElseIf myFile.DateLastModified > newestFile.DateLastModified Then
                    Set newestFile = myFile
                End If
        End Select
    Next
        
                
        If Not newestFile Is Nothing Then
            
            Application.Workbooks.Open newestFile.Path
            Set wb = Application.Workbooks(newestFile.Name)
            Set ws = wb.Sheets("Store Summary ")
        End If


End Sub

Open in new window

0
Comment
Question by:jmac001
6 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
Comment Utility
Handling the Open event (see the dropdown boxes at the top of the VBA environment) you can just do this...

Private Sub Workbook_Open() 
     Worksheets("theWorkSheetName").Activate
End Sub

Open in new window

0
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 400 total points
Comment Utility
Hi,

i made certain changes to the last part of your code:

        If Not newestFile Is Nothing Then
            
            Application.Workbooks.Open newestFile.Path , false 'added param FALSE to disable link updates
            Set wb = Application.Workbooks(newestFile.Name)
            Set ws = wb.Sheets("Store Summary")
			ws.activate ' you should activates selected sheet
        End If

Open in new window

0
 

Author Comment

by:jmac001
Comment Utility
Hi samo4fun,

That worked.  Any thoughts on the  Application.AskToUpdateLinks = False placement?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 15

Expert Comment

by:Haris Djulic
Comment Utility
I changed the following line to disable the links update :

Application.Workbooks.Open newestFile.Path , FALSE  ---added param FALSE to disable link updates
0
 
LVL 20

Assisted Solution

by:Ejgil Hedegaard
Ejgil Hedegaard earned 100 total points
Comment Utility
It does not matter where Application.AskToUpdateLinks = False is placed in the code.
It is not workbook specific, but change the Excel setting for opening all workbooks.

You probably have links to not available files, and that is another issue.
Excel ask if you want to Continue (= open the file without updating the links) or Edit the links.

Specify not to update links in the Open statement ignores all links, and that is probably not what you want.

To automatically update links, the solution Application.AskToUpdateLinks = False, with a "normal" Open statement, is the correct one to use, but you have to edit the links to work.
0
 

Author Closing Comment

by:jmac001
Comment Utility
Thanks samo4fun and Ejgil.  samo4fun I awarded you the majority of the points as both solutions you gave me did work. But I realized after trying the solution for the alerts that I still had issues which is why I awarded Ejgil 100 points for their explanation on why I would still be see the popup windows.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now