I wrote a VBA code in Excel to open mutiple Excel files, then open and update links in corresponding Powerpoint files by running ActivePresentation.UpdateLinks
The PPT files are processed one by one.
The problem: there are always some PPT files(not specific ones) fail to update links. And the first PPT always gets updated successfully.
I have to run the code again, and without exception, this time all PPT files get updated.
I want to run the code just one time without having this issue. How can I solve it?
Dim PPT As Object
Set PPT = CreateObject("Powerpoint.Application")
PPT.presentations.Open ("\someppt.pptm")
PPT.activepresentation.UpdateLinks
PPT.activepresentation.Save
PPT.activepresentation.Close
Related
I have an Excel VBA script that pulls data from a couple of files and builds a table in a certain format that suits the business need. I build the table in a hidden worksheet within my main Excel file and all works as intended.
However, I need to insert that table into a Word file. I know how to make a table, but I wanted to try to do an embedded Excel file instead because that way all of the formatting transfers.
I have created an accompanying Word file with a placeholder embedded Excel object. I gave the object (or "shape") a name in the Selection Pane. It's called InvoiceXLS.
I can get as far as opening the Word document and I know how to change basic OLEShapes / objects such as just changing text in named text boxes, but I can't figure out how to get a usable reference to the embedded sheet so that I can call Excel VBA commands on it, and basically replace it with the table I generated earlier in the script.
So far, this is how I open the link to the Word file:
Set wApp = CreateObject("Word.Application")
wApp.Visible = True
Set wDoc = wApp.Documents.Open(filename:=ThisWorkbook.path & "\TestAccount.docx")
With wDoc
.Shapes("InvoiceXLS").OLEFormat.Edit ' ???
' How do I get a Worksheet object that I can work with??
' Or, just paste in a whole table over top?
End With
Thanks in advance for any help!
I have a program in an Excel workbook that opens a Powerpoint-File, updates the links within this file and closes it after that. This works fine. Here is my problem: When the links are updated an Excel file with the source data is opened. After Powerpoint is closed this file stays open. I want it to get closed because I repeat this process for many files and I can't end up with hundreds of open Excel files.
I tried the following:
WBKs=Application.Workbooks.count
For i = WBKs to 1 Step -1
If Workbooks(i).Name<>ThisWorkbook.Name then
Workbooks(i).close savechanges:=False
End if
Next i
Now comes the weird part. Whenever I just run my code, WBKs always returns 1 and the Excel file only pops up after the code is finished. If I go through my code in debug mode it works. The workbook pops up as soon as I enter debug mode.
I tried Applicatio.Wait in the hope that the file would show after a second. The file only showed after the code was finished.
I tried a Do While Loop to wait until the file is open. Excel crashes because I never leave the loop.
Edit: I tried DoEvents as suggested. Does not work either.
This is just a workaround, but try using a brute force after x times your macro has run. Store that x somewhere in workbook, save. And kill excel process (all instances, including self) :
Dim sKill As String
sKill = "TASKKILL /F /IM excel.exe"
Shell sKill, vbHide
Found here : VBA script to close every instance of Excel except itself
When running your macro next time, you will use that x as a starting point for next PPT file to update.
I'm working on a macro to automatically update all of the linked charts in a presentation from their source Excel workbooks. My problem is that when the linked workbook cannot be found, executing the LinkFormat.Update method produces the standard "The linked file is not available...." dialog. This could result in the user having to dismiss the dialog dozens or even hundreds of times when updating a presentation.
Is there any way to suppress this dialog when updating a linked chart, either directly or by verifying the link source before attempting an update? The operation does not produce an error, so it can't be trapped. I'm using Chart.ChartData.IsLinked to check for and filter out charts that aren't linked at all, but I can't find any similar property or method that would allow me to check the status of an existing link before executing LinkFormat.Update. I would expect that setting Application.DisplayAlerts to ppAlertsNone would work, but ppAlertsNone is already the default, and setting it manually has no effect.
Linked shapes will be of type msoLinkedOLEObject or msoLinkedPicture (which you probably aren't concerned with). A linked shape's .LinkFormat.SourceFullname will give you the full path to the linked file, so something like this should get you going. The test for existence of the file's simplistic but it's a starting point:
For Each oSh In ActivePresentation.Slides(1).Shapes
If oSh.Type = msoLinkedOLEObject Then
If Len(Dir$(oSh.LinkFormat.SourceFullName)) > 0 Then
' do your thing
End If
End If
Next
Recently, I have a project need to automate a process by combining SSIS package and excel VBA macro into one. Below are the steps:
I have a SSIS package exporting all the view result to multiple individual file from sql server to excel. All the files are saved in same location.
I have one excel VBA macro perform cleaning to remove all the empty sheets in each exported excel file.
I also have a excel VBA macro perform merging task to merge all the excel file into in master excel file. This master excel file contains all the result set and each result set saved on different tabs accordingly.
Since I am manually running step 2 and step 3, so my question is how should connect step 2 and step 3 with step 1 to combine them as one automate process.
Please provide me advice on how likely this can be achieved! Thanks a lot.
The way to do this is to create a script task in your SSIS package.
Then, once inside the script task, you can call the Excel interop through the C# code of the script task. e.g. you can add a reference to Microsoft.Office.Interop. Once you are using that library in your C# code of the script task, you can add some code that will call the macro. e.g.
oExcel = CreateObject("Excel.Application")
oExcel.Visible = False
oBooks = oExcel.Workbooks
oBook = oBooks.Open(Dts.Variables("filePath").Value.ToString())
//Your macro here:
oExcel.Run("Yourmacro")
Then you could write code for the other workbooks aswell, for whatever automation you need after this - e.g. you can close the workbook and open another workbook, through the Excel automation as needed.
I encountered a strange error in an Excel 2007 add-in that seems to be reproducible with a few lines of macro code (Update: even without code, see below).
Open a new workbook and add the following code to the first worksheet.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.DisplayAlerts = False ' Suppress macro and overwrite warnings
ActiveWorkbook.SaveAs "test.xml", XlFileFormat.xlXMLSpreadsheet
End Sub
Now each change will save the workbook as an XML spreadsheet file.
However, when I open a second instance of Excel and copy a single cell from there to the auto-saving workbook Excel 2007 crashes. (I have also seen an RPC_E_SERVERFAULT error in a comparable situation.) In Excel 2010 the file is saved as expected.
Any ideas what might be the root cause for this behaviour and how to avoid it?
UPDATE
Seems like it's even worse: If I copy data from one Excel (2007) instance to another and save the target workbook as XML spreadsheet Excel crashes. I tried this on two machines, so is this a known bug?