Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 04-14-2025, 12:19 AM
BigMac'ro BigMac'ro is offline Updating tables in Word Windows 10 Updating tables in Word Office 2016
Novice
Updating tables in Word
 
Join Date: Feb 2025
Posts: 9
BigMac'ro is on a distinguished road
Default

Quote:
Originally Posted by Italophile View Post
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
the variable xlApp does not exist in this scope.

That's true, though i didn't run into a compile error when executing my code But you're right, it's cleaner like this:


Code:
Function WorkbookIsOpen(filePath As String, xlApp As Excel.Application) As Boolean
and when calling the function:


Code:
If Not WorkbookIsOpen(filePath, xlApp) Then
...
Quote:
Originally Posted by Italophile View Post
In your new variable declarations
Code:
Dim chartObj As Excel.chartObject
should be

Code:
Dim chartObj As Excel.Chart

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
I'm also wondering why the VBA editor won't let me write



Code:
Dim chartObj As Excel.Chart
but always corrects back to


Code:
Dim chartObj As Excel.chart
Quote:
Why aren't you simply using a template with Links to the Excel workbook & charts, which you could simply update and, if appropriate, break before saving the new document? That would make most of your code redundant and wouldn't require the use of bookmarks.
That would be possible if the Excel workbooks wouldn't change. In my case, the report gets regularly updated and so do the Excel files. The old Excel files are kept. For the report in January 2024, I have to refer to excel files called e.g. "202401_Data1.xlsx", "202401_Data2.xlsx",... One month later, it would be "202402_Data1.xlsx", "202402_Data2.xlsx",... That's why I came up with the "reference file" listing all paths to the relevant workbooks. Plus, there are several people working on the report, sometimes with somewhat inconsistent file-naming approaches I think it will be more easy to convince them to keep the reference file up to date than changing their file-naming habits...




(I now also added "Option Explicit" at the beginning of my code to avoid getting into troubles concerning variable declaration)
Reply With Quote
 

Tags
charts, copy, update

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating tables in Word Is there a way to stop macro modifications from undoing when Updating Word Linked Tables? 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
Updating tables in Word Word 2013 Fields not updating 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft