Solved

VBA - bypass the link update dialog box for the source file

Posted on 2011-09-28
12
206 Views
Last Modified: 2012-05-12
Hi,

I am copy some data from another workbook which apparently have links to another source. When I try to open this file (as usual) excel asks me to confirm wether or not I want to update the link.
Although user can simply say yes or no but i was wondering if its possible to by pass this one by saying 'dont update' -> for the links
Such that its not displayed to the user.  
Current status is,
   Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.Calculation = xlCalculationManual

I though it might help but it doesnt seem to work over the update link pop-up
It would be great if some one could post couple of lines required to achieve it.

Many thanks
0
Comment
Question by:SameerMirza
  • 6
  • 4
  • 2
12 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 400 total points
ID: 36717575
In the workbooks.Open method, specify updatelinks:=False
0
 
LVL 17

Assisted Solution

by:andrewssd3
andrewssd3 earned 100 total points
ID: 36717589
The second parameter of the Workbooks.Open method tells it whether to update links or not (True/False) - I think setting this to False should get rid of your message
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36717594
Like he just said...
0
 

Author Comment

by:SameerMirza
ID: 36717936
Thanks.
Can any one please tell me what the below code is doing and whats the first argument of GetOpenFileName()

where its defined as
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenFileName As OPENFILENAME) As Long
Sub test(sWks As String, sLoc As String)
    
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim FileDir As String
    Dim FilePos As Long
    Dim PrevFilePos As Long
    Dim oWks As Worksheet

    On Error GoTo Data_Err

    Set oWks = Worksheets(sWks)

    With OpenFile
        .lStructSize = Len(OpenFile)
        .hwndOwner = 0
        .hInstance = 0
        .lpstrFilter = "Excel Files" + Chr(0) + "*.xls" + _
            Chr(0) + "All Files (*.*)" + Chr(0) + "*.*" + Chr(0) + Chr(0)
        .nFilterIndex = 1
        .lpstrFile = String(4096, 0)
        .nMaxFile = Len(.lpstrFile) - 1
        .lpstrFileTitle = .lpstrFile
        .nMaxFileTitle = .nMaxFile
        .lpstrTitle = "Oil Index D-1 File"
        .flags = OFN_HIDEREADONLY + _
            OFN_PATHMUSTEXIST + _
            OFN_FILEMUSTEXIST + _
            OFN_ALLOWMULTISELECT + _
            OFN_EXPLORER
        lReturn = GetOpenFileName(OpenFile)

Open in new window

0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36717961
That's a completely different question!

It's an API function for getting a filename to open. The argument is a specific Type expected by the function - you should have it declared at the top of the module.
0
 

Author Comment

by:SameerMirza
ID: 36813577
Yes rorya
I understand that its different from the title but its basically this function that we are using to open the file. :)
I dont mind opening another thred for it as long as some one can help me out with it.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36813587
Why are you using API functions just to open a file? You can use Application.GetOpenFilename and then Workbooks.Open and then all your problems are solved with about 3 lines of code. :)
0
 

Author Comment

by:SameerMirza
ID: 36813657
It would helpful if you could confirm if takes a dir as a parameter.
That is by default would it go to the folder that I would pass in?

All I want to do is to let user pick a file from a default dir.
If this isnt the required function then it would be great if you could let me know which function can I use


thanks
0
 

Author Comment

by:SameerMirza
ID: 36813709
ok guys sorry for being so annoying.
At the end you have to you workbook.open to open the file :)
and its just second paramter that you have to turn off - updatelink:= false
0
 

Author Closing Comment

by:SameerMirza
ID: 36813715
thanks and appologies for being so annoying :)
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36813732
Yes, GetOpenFilename allows you to specify a full default path. :)
0
 

Author Comment

by:SameerMirza
ID: 36813778
Well in this case this API function is doing something like,
go to the default folder - (input parameter),
I guess its digging down to the currently updated folder ,
get the file picked up by the user and set some properties for 'OPENFILENAME' (object?)

its actually intresting.
I am not sure if I am interpreting it right but this is what it seems to be doing
I might open another thred just to get understanding of
OPENFILENAME - I guess its object
and function as given about - code section
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

705 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

12 Experts available now in Live!

Get 1:1 Help Now