DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

file path for excel file

Solved!
Go to solution

Hi Everyone,

I am writing and reading data from an Excel file (see code) and it works but I have to specify the path in the script and if I want to change the file I have to change the file path in the code.

I would like to create a window that pops and asks the user to pick the excel file he wants to work with, copy the path and replace

"C:\Users\Public\Documents\National Instruments\DIAdem 2012\Documents\Constant Radius\USED\Test.xlsx" by that path.

I hope someone can give me a hand with this.....

 

Thanks

Leo

 

Dim Excel,a Set Excel = CreateObject("Excel.Application") Excel.Visible = TRUE Call Excel.Workbooks.Open("C:\Users\Public\Documents\National Instruments\DIAdem 2012\Documents\Constant Radius\USED\Test.xlsx") a=Excel.ActiveSheet.Cells(1,1).Value Excel.ActiveSheet.Cells(1,4).Value = RV1(1) Excel.ActiveSheet.Cells(2,4).Value = RV1(2) Excel.ActiveSheet.Cells(3,4).Value = RV1(3) Excel.ActiveSheet.Cells(4,4).Value = RV1(4) Excel.ActiveSheet.Cells(5,4).Value = RV1(5) Excel.ActiveSheet.Cells(6,4).Value = RV1(6) Excel.ActiveSheet.Cells(7,4).Value = RV1(8) Excel.ActiveSheet.Parent.Saved = FALSE Excel.Quit Set Excel = Nothing

 

0 Kudos
Message 1 of 4
(6,248 Views)
Dim Excel,a 
Set Excel = CreateObject("Excel.Application")
Excel.Visible = TRUE
Call Excel.Workbooks.Open("C:\Users\Public\Documents\National Instruments\DIAdem 2012\Documents\Constant Radius\USED\Test.xlsx")
a=Excel.ActiveSheet.Cells(1,1).Value
Excel.ActiveSheet.Cells(1,4).Value = RV1(1)
Excel.ActiveSheet.Cells(2,4).Value = RV1(2)
Excel.ActiveSheet.Cells(3,4).Value = RV1(3)
Excel.ActiveSheet.Cells(4,4).Value = RV1(4)
Excel.ActiveSheet.Cells(5,4).Value = RV1(5)
Excel.ActiveSheet.Cells(6,4).Value = RV1(6)
Excel.ActiveSheet.Cells(7,4).Value = RV1(8)
Excel.ActiveSheet.Parent.Saved = FALSE
Excel.Quit
Set Excel = Nothing

 Hi,

I am just repasting the code. I don't know what happened earlier but everything went on the same line, sorry

0 Kudos
Message 2 of 4
(6,238 Views)
Solution
Accepted by topic author Leillo

Hi Leillo,

 

I believe this is what you're looking for:

 

DlgTitle = "Insert File Dialog Title Here..."
StartPath = ProgramDrv & "Examples\Data\"
FileExts = "*.XLSX,*.XLSX"
FileExts = "Excel Files,*.XLSX;*.XLS"
Call FileNameGet("Any", "FileRead", StartPath, FileExts, "Nul", True, DlgTitle)
IF DlgState = "IDCancel" THEN Call AutoQuit
DataFilePath = FileDlgFileName
MsgBox DataFilePath

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 3 of 4
(6,228 Views)

Thanks Brad, it worked OK

0 Kudos
Message 4 of 4
(6,212 Views)