Results 1 to 11 of 11

Thread: Exporting Excel application to another Excel file

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    5

    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

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Exporting Excel application to another Excel file

    Quote 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

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    5

    Re: Exporting Excel application to another Excel file

    Quote 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.

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    5

    Re: Exporting Excel application to another Excel file

    Quote 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".

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    5

    Re: Exporting Excel application to another Excel file

    Quote 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.

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    5

    Re: Exporting Excel application to another Excel file

    [QUOTE=koolsid]
    Quote 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.

  10. #10
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width