VBA: Automating Loading of Data from Excel into PowerPoint Internal Chart Data - excel

I am looking to script the automated loading of data from an Excel Worksheet directly into the embedded Chart Data Source within PowerPoint - as opposed to copying the chart in Excel and pasting the linked chart into PowerPoint.
I have attached a link to an image which demonstrates (I hope) my intention.
I tried to implement some of the code on :
www.think-cell.com/en/support/manual/exceldataautomation.shtml#x28-21500022.1
But not entirely sure if this is the right approach, plus I am having issues debugging the code for:
Dim tcaddin As Object
Set tcaddin = _
Application.COMAddIns("thinkcell.addin").Object
And genuinely confused as to where in my code to implement what it calls the signature:
tcaddin.UpdateChart( _
pres As PowerPoint.Presentation, _
strName As String, _
rgData As Excel.Range, _
bTransposed As Boolean _
)
Genuinely not sure if I've gone about this the wrong way or if it's even possible, but some new and exciting approaches would be massively appreciated!!

If you want to add parts of an excel document to a powerpoint, you can paste the data so that it embeds and links to that document.
https://support.office.com/en-ie/article/insert-excel-data-in-powerpoint-0690708a-5ce6-41b4-923f-11d57554138d
Look at the above link and try the section Link a section of data in Excel to PowerPoint.
Then everytime you open the powerpoint it will ask if you want to update the links that are attached to the excel document.

Related

How add Excel.ChartObject that is not a chart sheet with AddOleObject?

This is not a duplicate question because the other questions do not have solutions for regular chart objects but only cover chart sheets.
Question: I want to add an Excel chart (i.e. NOT a chart sheet) to PowerPoint by using AddOleObject. I do not want to use a clipboard solution for this.
I tried the following:
oSlide.Shapes.AddOLEObject(FileName:=$"{oChartObject.Parent.Parent.Path}\{oChartObject.Parent.Parent.Name}!{oChartObject.Parent.Name}!{oChartObject.Name}", Link:=Microsoft.Office.Core.MsoTriState.msoFalse)
the FileName:= results in the following string:
C:\Users\Me\Desktop\SomeWorkbook.xlsx!Sheet2!NameOfMyChartObject
But this fails (com exception E fail) and I do not understand how to fix it.

Editing Data within Excel Add In (UDF using Index/Match)

I'm a beginner at vba but have created a custom Add In in Excel with several User Defined Functions (UDF)...they are all working for multiple users but I can't figure out how to update the reference data in ThisWorkbook. Background: I have several clients within the same industry that each have a custom spreadsheets, however, the general excel functions and reference data (statistical rates etc) are the same so I have built UDF to automatically pull the rates/calculate results using index/match. What I can't figure out is how to update the reference data that I have saved in the Add In - "Rates" Sheet - I need to input a new rate on an annual basis (and adjust range) but I can't open/view the excel sheets in my Add In. Here is my code:
Function RATE1(Year As Double)
Dim WBT As Workbook
Dim WSD As Worksheet
Set WBT = ThisWorkbook
Set WSD = WBT.Worksheets("Rates")
RATE1 = Application.WorksheetFunction.Index(WSD.Range("R3:r25"), Application.WorksheetFunction.Match(Year, WSD.Range("N3:n25"), 0), 1)
End Function
Any help/suggestions are greatly appreciated. Thanks.
Open a spreadsheet that has a link to the add in. Open the VBA Editor. In project explorer you will see the add in shown. Click on this and then open up to ThisWorkbook. Click on this and then look in Properties explorer for the property "IsAddin". Set this to false and your add in will appear. Make your changes, then set the IsAddin Property back to True. Then save your changes by clicking on the add in in project explorer and then on the Save icon in the toolbar in the VB Editor.

Paste/Copy Range of Cells from Excel to a Bookmark in Word using WORD VBA

I am looking at inserting/pasting a range of text data (40 columns) from Excel into bookmarks in Word. Most of the answers are done using Excel VBA, which is so not practical for my use case as I will have the Word document open, add a button that would run this 'import data' macro. I actually already have a button in the doc that inserts images into bookmarks, so that's one more reason I don't want to do it via Excel VBA.
I know this is not great code, but for the lack of definite leads, I'm throwing it here and hope that this gives you an idea of what I'm trying to achieve:
Sub ImportData()
Workbooks.Open ("\Book2.xlsm")
ActiveWindow.WindowState = xlMinimized
ThisWorkbook.Activate
Windows("Book2.xlsm").Activate
Range("A1:AF1").Select
Selection.Copy
Documents("test.docm").Activate
Selection.GoTo What:=wdGoToBookmark, Name:="Overlay_1"
Selection.Paste
End Sub
PS: It would be great if I could sort of 'transpose' the 40 columns into rows as it is pasted in Word.
Here's an update to my code based off #Variatus 's advice:
Sub ImportData()
Dim wb As Workbooks
Dim ws As Worksheets
Dim objSheet As Object
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
wb.Open ("C:\Users\pc\Documents\Book2.xlsm")
Set objSheet = CreateObject("Excel.Application")
ActiveWindow.WindowState = xlMinimized
Set ws = Workbooks("Book2.xlsm").Sheets("Sheet1")
ws.Range("A1").Value.Copy
With objWord.ActiveDocument
.Bookmarks("Bookmark_1").Range.Text = ws.Range("A1").Value
End With
End Sub
I'm getting this error:
Runtime Error '91':
Object variable or With block variable not set.
Notice how I stuck with a single cell reference for now (A1). I'll just update my code as I learn along the way :)
When you click the button in your Word document you want the following sequence to be initiated.
Create an Excel application object. Make sure that a reference to Excel has been set (VBE > Tools > References) so that Excel's VBA objects are available.
Using the Excel application object, open the workbook. Create an object. Place the object in an invisible window.
Definitely forget about activating or selecting anything in either the workbook or your Word document. The latter is active and remains active from beginning to end. The bookmarks are points in your document you can reference and manipulate by name without selecting them. The Excel workbook is invisible. You can access any part of it using the Range object.
The data you want from your workbook are contained in Worksheets. Be sure to create an object for the worksheet you are about to draw data from.
Excel tables don't translate very well into Word tables. If you do want to go that way I suggest that you use VBA to create the table you want in Excel (transpose the data before you import them into Word). However, you may find it easier to first create the tables you want in Word and then just copy values from your Excel source into the word tables. That would involve taking one cell value at a time and placing it into one Word table cell. Transposing would be done by the algorithm you employ.
Close the workbook. Quit the Excel application. Set the Excel application = Nothing. At the end of your macro everything is as it was before except that your document has data in it which it didn't have before.
Each of the above six points will lead you to at least one question which you can ask here after you have googled the subject and written some code. In fact, I strongly urge you to create one Main procedure (the one which responds to your button click) and let that procedure call various subs which carry out the individual tasks and functions to support the subs. The smaller the parts you create the easier it is to write the code, to find questions to ask and get answers to them. If you plan your project well expect to have about 12 procedures in it by the time you are done. Good luck!

Chart is not copying correctly from Excel to Access

Using data from Access, I have created a line chart in Excel. When I go to copy/paste the chart into a report my DB, the image is not the same. But, if I paste the same image into a work doc or outlook email, it looks fine. The same distorted version appears if I paste it into msPaint. Please see the attached screenshots of the charts. The big issue is the x-axis labels. Here is my copy/paste code.
Dim objChart As Chart
objChart.CopyPicture xlScreen, xlBitmap, xlScreen
DoCmd.OpenReport ReportName:="rptDeptWindowChart", View:=acViewDesign
ctlC = Reports!rptDeptWindowChart.Controls.Count
Do
For Each ctl In Reports!rptDeptWindowChart
ctl.Name = "ctlDelPic"
DeleteReportControl "rptDeptWindowChart", "ctlDelPic"
Next
ctlC = Reports!rptDeptWindowChart.Controls.Count
Loop Until ctlC = 0
DoCmd.RunCommand acCmdPaste
Access is not well-known for it's charting capabilities. If I were you, I'd stick to using Access for managing large data sets, and export final results of queries to Excel, and do your charting/plotting/graphing in Excel. Word is great for creating documents, PowerPoint is great for presentations, etc. You need to use the right tool for the right job.

Excel 2010 - Data From Web creating a new file?

I am trying to set up a sheet in my excel Workbook where the data is from the web. That way I can click refresh and the data will be pulled from the site again, basically automating what is currently a new process.
Right now we are exporting the data from a site into an excel file and then copy/pasting it into the second workbook and generating our reports there, I want to avoid doing this, clicking refresh should refresh the data.
The data I am trying to pull is from the OnDemand JIRA application we are using to track our agile team process. (URL https://mycompany.atlassian.net/sr/jira.issueviews:searchrequest-excel-all-fields/10101/SearchRequest-10101.xls?tempMax=1000)
Now the problem is that if I select Data -> From Web in Excel 2010 and I enter the above URL, Excel always wants to save the data into another Excel file....is there any way I can have it insert the data in the workbook I already have open (the one I clicked Data -> From Web in?)? I can't seem to find any way to do this right now so any help is appreciated!
I don't know too much about REST but is there a better way to do this other than using Data -> From Web? Keep in mind I want to avoid the copy/paste of the data from one spreadsheet to another and the data will be refreshed weekly. Thank YOU!
This might get you started...
Sub DoUpdate()
Const URL As String = "https://mycompany.atlassian.net/sr/jira.issueviews:" & _
"searchrequest-excel-all-fields/10101/" & _
"SearchRequest-10101.xls?tempMax=1000)"
Dim wb As Workbook
Set wb = Workbooks.Open(URL) 'open workbook from web
'clear previous data
ThisWorkbook.Sheets("data").Range("A1:H200").ClearContents
'copy new data over
wb.Sheets(1).Range("A1").CurrentRegion.Copy _
ThisWorkbook.Sheets("data").Range("A1")
wb.Close False 'close and don't save any changes
End Sub

Resources