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

export and open excel file via macro

hi guys,

I made a macro that saves a chart to an excel doc' when the users press a button.

Now I need that when the user press the button it will open the excel file (with the chart values),quite similar to the

"send to excel" in the QV ,how can I do that?

THX

10 Replies
Not applicable
Author

Hello!
I do see your macros so the comparison with what I have done?

Daniela

Not applicable
Author

Hi,

the pseudo code for this would be something similar like this:

Dim objExcel
Set objExcel = CreateObject("Excel.Application")
-> copy chart to the desired sheet in Excel-application
-> levae excel open ...

OR

your script for saving the chart to excel
then
Set objExcel = CreateObject("Excel.Application")
objExcel.OpenWorksheet(yourFilename) <-- sorry I cannot remember the exact syntax for the method OpenWorksheet, you shold google that ..

Hope this helps ...

Best regards

Stefan

Not applicable
Author

well guy,I search but I'm not as good in VB....

See the attached file---->after pressing the blue buttom the chart saved in the desired directory,I want that the file

will also open,I wrote some code but nothing happens.....

**) for some reason the file couldn't attach Confused...I will try again soon

Anonymous
Not applicable
Author

Like Stefan said, if you already have your export code in place you can just add a few rows for launching the excel document that you just exported.

Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open("C:\Folder\Document.xls")
objExcel.Visible = True

I noticed I had to add the last row for Excel to show. The process was launched but not shown in the gui.

Not applicable
Author

I tried.....its not working.

the Qv can't execute the line :

Set

objexcel=GetObject("Excel.Application.")

Not applicable
Author

This one works for me:

sub export_summary

set v = ActiveDocument.Variables("QvWorkPath")

set XLApp = CreateObject("Excel.Application")
XLApp.Visible = false
set ExcelDoc = XLApp.Workbooks.Add

ExcelDoc.Sheets(1).activate

set obj1 = ActiveDocument.getsheetobject("CH_Cases")
obj1.CopyTableToClipboard true
ExcelDoc.Sheets(1).cells(1,1).select
ExcelDoc.Sheets(1).paste
ExcelDoc.Sheets(1).Rows("1:1").Font.Bold = True
set obj1 = nothing

"CH_Cases": replace it with your object ID

ExcelDoc.Sheets(1).cells(1,1).select: means that it will start in A1. If you want it to start in e.g. A2 you write 2,1

Not applicable
Author

try this (it works for me)

dim ExcelApp, ExcelWB

set ExcelApp = createobject("Excel.Application")

ExcelApp.visible = true

set ExcelWB = ExcelApp.Workbooks.Open(c:\FileName)









Anonymous
Not applicable
Author

Make sure you Allow System Access for the macro in the Macro module too. Otherwise you will not be allowed to create objects.

Anonymous
Not applicable
Author

Hi,

This macro works for me, but I would like to save the document on my computer. How to do that?

Cheers,

Henco