Page 1 of 1

Automated File Path Directory for Save As Popup

Posted: Tue 13. Nov 2018, 17:13
by yhadad
Hello,

I have an automated plotter that records data once I start a macro to run a test. Once the macro completes the loop, a Save As popup window will appear so that the user can give the data file a name before saving it as shown in the code below.

Code: Select all

Dim PlotDoc, plotter

Set PlotDoc = Documents.Open("Speed.plt")

If Not PlotDoc Is Nothing Then
     Set plotter = PlotDoc.ActiveWindow.Object
     plotter.ClearAll
     plotter.Start
End If

////(My Loop Code)////

     Plotter.Stop

PlotDoc.IsActive = True
ExecuteCommand "FilesSaveAs"
Now I need to program it to save to a specific file directory for example if the test passes, then it will have a SaveAs popup that will automatically lead to the file directory: C:\PASS and if the test will fail then a SaveAs popup will appear and automatically lead to file directory: C:\FAIL.

Is there a way of achieving that?

Thanks in advance

Kind Regards,

Yousif

Re: Automated File Path Directory for Save As Popup

Posted: Wed 14. Nov 2018, 09:28
by M.Gerber
Hello Yousif,

Why not using the Save Method of the Document object? There you can specify a file name and a path. According to your if clause you could use the different paths and file names. Maybe in that case it wouldn't even be necessary to prompt the user with Save As anymore.

The path to the help, I've mentioned in the other thread, gives you the needed information about the Document object.

Kind regards
Mark

Re: Automated File Path Directory for Save As Popup

Posted: Wed 14. Nov 2018, 18:34
by yhadad
Hi Mark,

The reason why I want a popup SaveAs with automated file directory path to a "pass" or "fail" folder is because I will have a technician at the plant that will test the e-axle and then during the popup, he will then use a QR scanner to scan the axle which will input the serial number of the axle before saving it. Thank you.

Regards,

Yousif

Re: Automated File Path Directory for Save As Popup

Posted: Thu 15. Nov 2018, 12:33
by M.Gerber
A possiblity to give a new name or just a new path as parameter to the Save As dialog does not exist.

Maybe you could go another way:
  1. Use the general InputBox function of VBscript to get the scanned serial number.
  2. Assemble the full path and name of the file to be saved in the script.
  3. Use the Save method of the Document object (i.e. PlotDoc.Save).
Hope this approach helps.

Mark

P.S.: The PCAN-Explorer Help (F1) also contains the full scripting reference by Microsoft (lowest main entry in the help's table of contents). For example, you will find the explenation for the InputBox function there.

Re: Automated File Path Directory for Save As Popup

Posted: Thu 15. Nov 2018, 21:36
by yhadad
Thank you Mark,

I took your recommendation and made my code to work :) Here it is below incase someone else needs help to use my code as an example.

Code: Select all


Dim PlotDoc, plotter, Input, fpath

Set PlotDoc = Documents.Open("Speed.plt")

If Not PlotDoc Is Nothing Then
     Set plotter = PlotDoc.ActiveWindow.Object
     plotter.ClearAll
     plotter.Start
End If

////(My Loop Code)////

     Plotter.Stop
 PlotDoc.IsActive = True

Input = InputBox("Enter Serial Number")
Input = Input & ".plt"
fpath = "C:\PASS\"
PlotDoc.Save fpath & Input
MsgBox (You entered: " & Input)