Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

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

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
SameerMirza
Asked:
SameerMirza
  • 6
  • 4
  • 2
2 Solutions
 
Rory ArchibaldCommented:
In the workbooks.Open method, specify updatelinks:=False
0
 
andrewssd3Commented:
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
 
andrewssd3Commented:
Like he just said...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
SameerMirzaAuthor Commented:
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
 
Rory ArchibaldCommented:
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
 
SameerMirzaAuthor Commented:
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
 
Rory ArchibaldCommented:
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
 
SameerMirzaAuthor Commented:
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
 
SameerMirzaAuthor Commented:
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
 
SameerMirzaAuthor Commented:
thanks and appologies for being so annoying :)
0
 
Rory ArchibaldCommented:
Yes, GetOpenFilename allows you to specify a full default path. :)
0
 
SameerMirzaAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now