Using ExecuteExcel4Macro() opens the file browser

elprey

New Member
Joined
Feb 17, 2016
Messages
2
Hi everyone,

I'm a bit new to VBA. I'm attempting to create an excel 2010 VBA script which grabs a the value of a single cell from a closed existing workbook.

Code:
[LIST]
[*][COLOR=#333333]Private Sub CommandButton1_Click()[/COLOR]

[*][COLOR=#333333] [/COLOR]

[*][COLOR=#333333]    Application.ScreenUpdating = False[/COLOR]

[*][COLOR=#333333] [/COLOR]

[*][COLOR=#333333]    p = "U:\path"[/COLOR]

[*][COLOR=#333333]    f = "File Name.xlsm"[/COLOR]

[*][COLOR=#333333]    s = "Sheet Name"[/COLOR]

[*][COLOR=#333333]    a = "A1"[/COLOR]

[*][COLOR=#333333]   [/COLOR]

[*][COLOR=#333333]    ret = "'" & p & "[" & f & "]" & s & "'!" & Range(a).Address(True, True, -4150)[/COLOR]

[*][COLOR=#333333]   [/COLOR]

[*][COLOR=#333333]    CellValue = ExecuteExcel4Macro(ret)[/COLOR]

[*][COLOR=#333333]    Range("A1").Value = CellValue[/COLOR]

[*][COLOR=#333333]   [/COLOR]

[*][COLOR=#333333]End Sub[/COLOR]
[/LIST]

The code works just as expected other than the fact that when I run it, it opens up the file browser. From there, I have found that if I select a file, it will read the cell value for that file. If I hit cancel, it will read the cell value of the variable I've selected.

I'd like this script to read many files automatically, so it cannot be opening the file browser for each cell value it attempts to get. Has anyone see this problem before, and do you know any solutions?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hello,
I'm stuck with the same problem of file browser opening unexpectedly.
Could you please share your solution
BR/
 
Upvote 0
Hello,
I'm stuck with the same problem of file browser opening unexpectedly.
Could you please share your solution
BR/

This answer is from a similar question on StackOverflow
answered Feb 13 '12 at 14:07


Siddharth Rout


The open file dialog box is being showed to you because the path variable "p" doesn't have a "" in the end ;)
 
Upvote 0
The slash is missing...
The open file dialog box is being showed to you because the path variable "p" doesn't have a "" in the end :wink:
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top