Variables as parameters

3 posts / 0 new
Last post
marconb10
Offline
Joined: 11/13/2019 - 12:39
Variables as parameters

Hi! Can you help me!?
I'm learning how to do some scripts, but really (really) new to it.
I'm currently trying to create a script that uses the same file to do different things.
Now I'm oppening the file a lot of times to get it's different sheets.
Is that possible to create a function to open the file, and then get those different sheets? Probably passing the address of the file as a parameter.
</code>
Sub Main
Call OpenFile()
Call ExcelImport_sheet1()
Call ExcelImport_sheet2()
Function OpenFile
dbName1 = InputBox ("Insert file address")
End Function
Function ExcelImport_sheet1
dbName1 = OpenFile(dbName1) 'I need something like that
Set task = Client.GetImportTask("ImportExcel")
task.FileToImport = dbName1
task.SheetToImport = "test"
task.OutputFilePrefix = "A2_test"
task.FirstRowIsFieldName = "TRUE"
task.EmptyNumericFieldAsZero = "FALSE"
task.PerformTask
dbName = task.OutputFilePath("At_test")
Set task = Nothing
Client.OpenDatabase(dbName)
End Function
end Sub
<code\>
I saw an example here (https://www.ideascripting.com/forum/passing-variables-functions-and-subs)  but I didn't really understand it.Would you mind helping me out, please?

marconb10
Offline
Joined: 11/13/2019 - 12:39

Sorry, already solved it with:
Function OpenFile
dbName1 = InputBox ("file address")
ExcelImport(dbName1)
(: 

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

That is great that you figured it out, good luck with your project.