|
-
Jun 16th, 2008, 10:16 AM
#1
Thread Starter
New Member
Exporting Excel chart into file using VB
Hello,
I'm somewhat of a novice to VB, and I have a question...I am trying to export a formula-driven Excel chart into another Excel document with no formulas (i.e. values only). Furthermore, I would like to be able to automatically generate the filename AND sheet name of the exported file through the original Excel file.
Any advice would be appreciated.
Thanks,
Mark
-
Jun 16th, 2008, 01:05 PM
#2
Re: Exporting Excel application to another Excel file
 Originally Posted by yankeeyosh26
Hello,
I'm somewhat of a novice to VB, and I have a question...I am trying to export a formula-driven Excel chart into another Excel document with no formulas (i.e. values only). Furthermore, I would like to be able to automatically generate the filename AND sheet name of the exported file through the original Excel file.
Any advice would be appreciated.
Thanks,
Mark
This will help you in exporting a formula-driven Excel chart as gif image and then you can call it back to the new document...
http://www.vbforums.com/showpost.php...68&postcount=5
generating a new filename and sheetname shouldn't be difficult. it all depends on how do you want to rename it... Do you want to use the dates or specific format etc etc...
Hope this helps...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 16th, 2008, 01:18 PM
#3
Thread Starter
New Member
Re: Exporting Excel application to another Excel file
 Originally Posted by koolsid
This will help you in exporting a formula-driven Excel chart as gif image and then you can call it back to the new document...
http://www.vbforums.com/showpost.php...68&postcount=5
generating a new filename and sheetname shouldn't be difficult. it all depends on how do you want to rename it... Do you want to use the dates or specific format etc etc...
Hope this helps...
I tried this, and I got an error on the line where mychart is set (Run-time error '1004': Application-defined or object-defined error). Any idea what is going on?
I want to rename the files based on two input parameters that can be entered on the main spreadsheet (one for the filename, one for the sheetname).
Thanks.
-
Jun 16th, 2008, 01:27 PM
#4
Re: Exporting Excel application to another Excel file
Did you replace "Chart 1" with the name of your chart?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 16th, 2008, 01:36 PM
#5
Thread Starter
New Member
Re: Exporting Excel application to another Excel file
 Originally Posted by koolsid
Did you replace "Chart 1" with the name of your chart?
I think so. I tried it in two different ways (in the project window, the sheet I am trying to export is called "S (chart)", where "chart" is what I called the chart...no idea why "S" is called "S" and not "Sheet1". But now the error I am getting is "Unable to get the ChartObjects property of the Worksheet class".
-
Jun 16th, 2008, 02:45 PM
#6
Re: Exporting Excel application to another Excel file
ok
here it is...
Press Alt-F11 to activate the Visual Basic editor. Select your workbook in the Projects window, and choose Insert, Module to insert a new VBA module. Then type the following four-line procedure into the module:
Code:
Sub exportmychart()
'Replace the path below with your path
Fname = "S:\New Folder\" & ActiveChart.Name & ".gif"
ActiveChart.Export FileName:=Fname, FilterName:="GIF"
End Sub
After the macro is entered, reactivate Excel and click the chart to be saved. Press Alt-F8 to display the Macro dialog box. Select the exportmychart macro and click Run. your chart will be save in the location you specified...
Hope this helps
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 16th, 2008, 02:54 PM
#7
Thread Starter
New Member
Re: Exporting Excel application to another Excel file
 Originally Posted by koolsid
ok
here it is...
Press Alt-F11 to activate the Visual Basic editor. Select your workbook in the Projects window, and choose Insert, Module to insert a new VBA module. Then type the following four-line procedure into the module:
Code:
Sub exportmychart()
'Replace the path below with your path
Fname = "S:\New Folder\" & ActiveChart.Name & ".gif"
ActiveChart.Export FileName:=Fname, FilterName:="GIF"
End Sub
After the macro is entered, reactivate Excel and click the chart to be saved. Press Alt-F8 to display the Macro dialog box. Select the exportmychart macro and click Run. your chart will be save in the location you specified...
Hope this helps 
When I click F11, I get a new tab that says Chart1. Just FYI, this is just a table on a normal Excel sheet; not a chart. Sorry if there is any confusion.
Anyway, when I tried running this, I got Run-time error '91': Object variable or With block variable not set.
-
Jun 16th, 2008, 04:14 PM
#8
Re: Exporting Excel application to another Excel file
[QUOTE=yankeeyosh26]When I click F11, I get a new tab that says Chart1. QUOTE]
1) You need to click Alt plus F11 and not F11 to access the VBA Editor
Just FYI, this is just a table on a normal Excel sheet; not a chart. Sorry if there is any confusion.
What do you mean????
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 16th, 2008, 04:31 PM
#9
Thread Starter
New Member
Re: Exporting Excel application to another Excel file
[QUOTE=koolsid]
 Originally Posted by yankeeyosh26
When I click F11, I get a new tab that says Chart1. QUOTE]
1) You need to click Alt plus F11 and not F11 to access the VBA Editor
What do you mean????
Whoops...never mind...I misread, and only pressed F11. I am still getting that runtime error. Under Fname, I assume that's where the file is to be sent, right? I'm just putting it in my C drive, but for some reason, it is giving me that error.
Also, from what I have read, ActiveChart is used for embedded charts...I really apologize for the nomenclature; there are no "charts" anywhere in this application. It is all just formulas. I simply want to export the results into another spreadsheet (without formulas).
Last edited by yankeeyosh26; Jun 16th, 2008 at 04:43 PM.
-
Jun 16th, 2008, 05:37 PM
#10
Re: Exporting Excel application to another Excel file
At the end what you want is to copy a range of cells then paste as values to another workbook.
-
Jun 17th, 2008, 02:28 AM
#11
Re: Exporting Excel application to another Excel file
@yankeeyosh26, Please dont post duplicate threads. Dup thread deleted.
Thanks Anhn.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|