LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Passing arguments into function to bring data array from closed wb

OK, I admit defeat...

I'm trying to allow a user to select a workbook, then bring in an array of
data from a (currently) hard coded sheetname and range.

Here's my code:

Sub GetArrayFromASelectedWorkbook()
Range("Target").ClearContents
sfilename = Application.GetOpenFilename(filefilter:="Excel Files
(*.xls),*.xls", MultiSelect:=False)
If sfilename = False Then 'User DIDN'T select a file
MsgBox ("No file selected.")
Else 'User DID select a file
GetArrayFromAUserSelectedWorkbook GetWorkbookName(sfilename,
"Sheet1", "A1:A10")
End If
End Sub

Function GetArrayFromAUserSelectedWorkbook(sfilename As Variant, _
SheetName, _
CellRange As String)
With ActiveSheet.Range(CellRange)
.FormulaArray = "='" & GetPath(MyFileName) & _
"[" & GetFileName(MyFileName) & "]" & SheetName & "'!" & CellRange
'.Value = .Value 'Convert array formulae to values
End With

End Function

However, when I run it, I'm getting "ByRef Argument Type Mismatch" with
"sfilename" highlighted in the row of the sub where the Function is called.
The variable "sfilename" is declared as public variant at the beginning of
the module.

I've banged my head against a brick wall so much that my employers are suing
me for damage to company property.

Can anyone help, please?

Thanks in advance..

Pete
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array function with more than 29 arguments [email protected] Excel Discussion (Misc queries) 2 April 15th 07 08:18 PM
Array function with more than 29 arguments [email protected] Excel Discussion (Misc queries) 3 April 15th 07 03:40 PM
Passing Arguments in Excell function UB Excel Discussion (Misc queries) 2 February 13th 07 03:19 PM
passing reference arguments to VBA function Mezon Excel Programming 2 August 28th 04 04:49 PM
Passing array to a function GB[_3_] Excel Programming 3 October 21st 03 09:59 AM


All times are GMT +1. The time now is 06:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"