![]() |
|
#1
|
|||
|
|||
![]()
There is a compile error in the code you have posted for Function WorkbookIsOpen.
Code:
Set wb = xlApp.Workbooks(filePath) ' Try to get the workbook In your new variable declarations Code:
Dim chartObj As Excel.chartObject Code:
Dim chartObj As Excel.Chart |
#2
|
|||
|
|||
![]() Quote:
That's true, though i didn't run into a compile error when executing my code ![]() Code:
Function WorkbookIsOpen(filePath As String, xlApp As Excel.Application) As Boolean Code:
If Not WorkbookIsOpen(filePath, xlApp) Then ... Quote:
I tried this, but then in this block it somehow jumps to the "else" condition and the message box is displayed Code:
If Not chartObj Is Nothing Then ' Copy the chart as an image 'chartObj.CopyPicture Appearance:=1, Format:=2 ' xlScreen, xlPicture chartObj.ChartArea.Copy 'chartObj.Copy ' Paste into Word if bookmark exists If ActiveDocument.Bookmarks.Exists(wordBookmark) Then Set bmRange = ActiveDocument.Bookmarks(wordBookmark).Range bmRange.Paste ActiveDocument.Bookmarks.Add wordBookmark, bmRange ' Re-add the bookmark after paste End If Else MsgBox "Chart '" & rangeOrChart & "' not found in sheet '" & sheetName & "'", vbExclamation End If Code:
Dim chartObj As Excel.Chart Code:
Dim chartObj As Excel.chart Quote:
![]() (I now also added "Option Explicit" at the beginning of my code to avoid getting into troubles concerning variable declaration) |
#3
|
||||
|
||||
![]() Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
![]() Quote:
Thanks for the input, macropod, that's for sure something I will think about! ![]() For the moment, I could achieve what I wanted to do with graphs. As often, a small mistake was hindering me: I noticed the graphs I am working with are not of type chartObject or Chart, but they are actually shapes! Therefore, the code in my previous post always jumped to the "else" condition. I replaced this code block and now loop through the shapes: Code:
Dim shp As Excel.Shape For Each shp In xlSheet.Shapes If shp.Type = msoChart And shp.Name = rangeOrChart Then shp.Copy If doc.Bookmarks.Exists(wordBookmark) Then Set bmRange = doc.Bookmarks(wordBookmark).Range bmRange.Paste doc.Bookmarks.Add wordBookmark, bmRange End If chartFound = True Exit For End If Next shp Thanks again to both of you for your valuable guidance! Now, let's go for the tables in the document ![]() |
#5
|
||||
|
||||
![]() Quote:
What is more, with a little discipline, you could do all this with no VBA code at all! All that would require is that the source files always use the same worksheet & workbook names and are stored in the same folder.* If the ranges in those workbooks expand/contract, simply used named ranges and link to those. That way, whenever you create a new document based on the Word template, it can automatically update the links to the data. You can then break the links (for which you might use a trivial macro that executes before the document is first saved). *If necessary because the individual monthly files only contain the data for that month, this might be done by making copies of the source files once they've been prepared, renaming the copies with the standard names, then copying them to the required folder.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
![]()
It happens and is of no consequence. What is essential is that the object/datatype is valid. You can use IntelliSense or the Object Browser for that.
|
![]() |
Tags |
charts, copy, update |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
soroush.kalantari | Word VBA | 3 | 06-27-2021 06:15 PM |
Problem With Updating Linked Excel Tables in Word 2013 | maverick1714 | Word | 6 | 09-30-2014 12:30 AM |
![]() |
awaywithpixie | Word | 1 | 09-10-2013 10:35 AM |
Updating lists of figures/Tables in a protected document | IHARKIS | Word | 0 | 03-02-2011 04:39 AM |
Auto-updating basic math functions & cross-referencing tables | FranklinBluth | Word Tables | 13 | 11-19-2009 10:26 AM |