Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Open .csv file after Export with Macro

Hello,

I have the following script to save a .csv file to a local harddrive. This works fine, however I am trying to figure out a way to make the .csv file open right after pressing the export button. What can I add to my script to make this happen? I am new to vba but I really want this to work.

The code:

Sub save

'MM_DD_YYYY

if len(replace(date,"/","_")) = 9 then

  datenow = "0" & replace(date,"/","_")

else

  datenow = replace(date,"/","_")

end if

'hhmmss AM/PM

if len(replace(time,":","")) = 8 then

  timenow = "0" & replace(time,":","")

else

  timenow = replace(time,":","")

end if

'Download Sheet ojbect data to CSV

set sObject = ActiveDocument.GetSheetObject("CH83")

sObject.Export "G:\QlikviewData\" & Right(datenow,4) & "\" & datenow & "_" & timenow & ".csv", ", "

End Sub

3 Replies
jerrysvensson
Partner - Specialist II
Partner - Specialist II

Five seconds on Google gave me this:

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "notepad.exe c:\text.txt"
Set oShell = Nothing

Not applicable
Author

Ok I am really new to this. First time I use it. It would look like this?

I get this error: Object required: 'WScript'.

Sub save

'MM_DD_YYYY

if len(replace(date,"/","_")) = 9 then

  datenow = "0" & replace(date,"/","_")

else

  datenow = replace(date,"/","_")

end if

'hhmmss AM/PM

if len(replace(time,":","")) = 8 then

  timenow = "0" & replace(time,":","")

else

  timenow = replace(time,":","")

end if

directory = "G:\QlikviewData\" & Right(datenow,4) & "\" & datenow & "_" & timenow & ".csv"

'Download Sheet ojbect data to CSV

set sObject = ActiveDocument.GetSheetObject("CH86")

sObject.Export "G:\QlikviewData\" & Right(datenow,4) & "\" & datenow & "_" & timenow & ".csv", ", "

'Open the file.

Dim oShell

Set oShell = WScript.CreateObject ("WScript.Shell")

oShell.run "notepad.exe directory"

Set oShell = Nothing

End Sub

cwolf
Creator III
Creator III

Hi,

Use

ActiveDocument.GetApplication.Launch "c:\temp\test.csv",""  to open it with default application for csv, ig Excel or

ActiveDocument.GetApplication.Launch "notepad.exe","c:\temp\test.csv" to open it in Notepad.

Regards

Christian