Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Does anyone know if it's possible to run the Word "Save as Picture" dialog from VBA?
Note:
I've searched high and low to no avail, suggesting it just may not be possible.
Still, thought it worth at least asking.
To clarify (as requested): This question is simply as asked.
At the time of asking, I could not find an answer to that anywhere. At the time of this editing, this is the only place I know of that answers this question (i.e. the basic question of can this be done, and if so how?).
As it turns out, yes it can be done (see below for how). And, while there may be other ways to do something similar by evoking architecturally different approaches (which I had already seen at the time of asking), they don't answer the question as asked.
Now, I can't see what's unclear about that or why it needs or more details.
So now I ask: Is there something fundamentally wrong with asking a question like this here on SO?
Turns out the solution was there, just hard to find. While the control isn’t on the ribbon, it still exists in the CommandBars. I managed to expose that by dumping out a list of all CommandBar controls (to find it and get the id). So, the solution is:
''' Note: Picture must be selected first
CommandBars.FindControl(ID:=5736).Execute
You can use PowerPoint to export the graphic. Here's a macro from a recent project that exports a map of the world. The Word graphics are EMF files:
Public Sub ExportMap()
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim pptShapeRange As PowerPoint.ShapeRange
Dim Path$, File$
Dim oRange As Range
Application.ScreenUpdating = False
myDate$ = Format(Date, "m-d-yyyy")
Set pptApp = CreateObject("PowerPoint.Application")
Path$ = ActiveDocument.Path & Application.PathSeparator
File$ = "WorldMap " & myDate$ & ".png"
Set pptPres = pptApp.Presentations.Add(msoFalse)
Set oRange = ActiveDocument.Bookmarks("WholeMap").Range
oRange.CopyAsPicture
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
On Error Resume Next
With pptPres.PageSetup
.SlideSize = 7
.SlideWidth = 1150
.SlideHeight = 590
End With
Set pptShapeRange = pptSlide.Shapes.PasteSpecial(ppPasteEnhancedMetafile, Link:=msoFalse)
pptSlide.Export Path$ & File$, "PNG"
pptApp.Quit
Set pptPres = Nothing
Set pptApp = Nothing
Set pptSlide = Nothing
Application.ScreenUpdating = True
MsgBox "All done! Check the folder containing this template for a file called '" & File$ & "'."
End Sub
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
I have the correct VBA to send email using gmail in an access database using a command button. Is there a way to populate the .To using a field on a form? I'd like to use fields on the form in the body of the message also. Is this possible?
I tried inserting the fields as I did using Outlook, but nothing worked.
Dim NewMail As CDO.Message
Dim mailConfig As CDO.Configuration
Dim fields As Variant
Dim msConfigURL As String
On Error GoTo Err:
Set NewMail = New CDO.Message
Set mailConfig = New CDO.Configuration
' load all default configurations
mailConfig.Load -1
Set fields = mailConfig.fields
'Set All Email Properties
With NewMail
.Sender = "xxxx#gmail.com"
.From = "xxxx"
.To = Left([emailadd], InStr([emailadd], "#"))
.CC = ""
.BCC = ""
.Subject = "Demo Spreadsheet Attached"
.Textbody = "Let me know if you have questions about the attached spreadsheet!"
End With
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can I send an email through an account using MS Access VBA? I know this question is vague but it's so hard to find the relevant information online that isn't outdated in some way.
EDIT: I don't mean to be rude to those who are answering, but I am using MS Access. I cannot write the actual code in Outlook VBA.
Add a reference to the Outlook object model in the Visual Basic editor. Then you can use the code below to send an email using outlook.
Sub sendOutlookEmail()
Dim oApp As Outlook.Application
Dim oMail As MailItem
Set oApp = CreateObject("Outlook.application")
Set oMail = oApp.CreateItem(olMailItem)
oMail.Body = "Body of the email"
oMail.Subject = "Test Subject"
oMail.To = "Someone#somewhere.com"
oMail.Send
Set oMail = Nothing
Set oApp = Nothing
End Sub
Here is email code I used in one of my databases. I just made variables for the person I wanted to send it to, CC, subject, and the body. Then you just use the DoCmd.SendObject command. I also set it to "True" after the body so you can edit the message before it automatically sends.
Public Function SendEmail2()
Dim varName As Variant
Dim varCC As Variant
Dim varSubject As Variant
Dim varBody As Variant
varName = "james#yahoo.com"
varCC = "billy#gmail.com, joe#yahoo.com"
'separate each email by a ','
varSubject = "Hello"
'Email subject
varBody = "Let's get ice cream this week"
'Body of the email
DoCmd.SendObject , , , varName, varCC, , varSubject, varBody, True, False
'Send email command. The True after "varBody" allows user to edit email before sending.
'The False at the end will not send it as a Template File
End Function
I'm experiencing SLOW changing, NOT updating, the links in powerpoint presentation for linked objects.
Sample codes are as below:
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.Type = msoLinkedOLEObject Then
Src_Old = Split(shp.LinkFormat.SourceFullName, "!")(0)
Src_New = Src_Path & "\" & Src_Book_Name
shp.LinkFormat.SourceFullName = Replace(shp.LinkFormat.SourceFullName, Src_Old, Src_New)
End If
Next shp
Next sld
During each iteration, the external source file will be reopen and the link will be updated, which significantly slow down the running. So the questions are:
Is there anyway to force NOT updating the link but just change the texts for SourceFullName?
Even if the answer is NO, is there anyway to stop reopening the external source files each iteration?
Thanks in advance.
I experienced the same problem. This single command line was taking up to 16 seconds to execute. Changing the update method to manual improved to 11 seconds. What really solved was opening the reference file in backgound, without even showing to user, in read only node. Down to 0.6 seconds. Also valid to the update method.
Dim xlApp As Object
Dim xlWorkBook As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
xlApp.DisplayAlerts = False
Set xlWorkBook = xlApp.Workbooks.Open(strDBPath, False, True)
When you finish dont forget to clean up the mess.
xlWorkBook.Close
Set xlWorkBook = Nothing
xlApp.Quit
Set xlApp = Nothing
Can you try switching to manual update mode by using this before changing the SourceFullName property:
shp.LinkFormat.AutoUpdate = ppUpdateOptionManual
And then using the Update method to manually refresh the content when needed:
shp.LinkFormat.Update
You might also be able to use the BreakLink method but I'm not sure if this is what you want:
shp.LinkFormat.BreakLink
Thanks in advance for any help you can give me.
I'm trying to create a VB application that will open an existing Word document, make some changes and save it with a new file name. Making the changes to the document is easy. Saving the document seems like it should be just as easy but there is one serious problem. When I try to save the document, the save as dialog opens. This is supposed to be automated so that doesn't work. I have tried a whole bunch of variations of:
Sub Main()
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim fileName As String
Dim templateName As String
Dim newFileName As String
'Start Word and open the document template.
oWord = CreateObject("Word.Application")
oWord.Visible = False
oWord.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
templateName = "C:\tmp\template.dotx"
fileName = "C:\tmp\document.docx"
newFileName = "C:\tmp\new document.docx"
oDoc = oWord.Documents.Add(templateName)
'oDoc = oWord.Documents.Open(fileName) I have tried both using a template and opening a docx file.
<make changes>
oDoc.SaveAs2(newFileName)
oWord.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
oWord.Application.Quit()
oWord = Nothing
End Sub
It always stops here:
oDoc.SaveAs2
and opens the save as dialog. I need to find a way to suppress the save as dialog or a new way of editing the word files. Everything I have found so far about the problem has either not been solved/updated or was related to Word addins. I don't have any of the addins that people said caused the problem. To be safe, I disabled all word addins.
I would appreciate it if anyone has either solved it or has a different approach. I'm not stuck on the idea of using VB. The only reason I'm going this route is because I think it gives me the best library for editing charts and formatting the documents.
Thanks, Steve
I found the problem. The answer lies in what I was doing in the part I omitted where I was making changes to the document. Part of those changes are to update data in the charts in the document. I had something like:
For Each oShape As Word.InlineShape In oDoc.InlineShapes
If oShape.HasChart And oShape.Range.Bookmarks.Item(1).Name = "ChartName" Then
Console.WriteLine("Updating ChartName")
Dim oWorkbook As Excel.Workbook
oWorkbook = oShape.Chart.ChartData.Workbook
oWorkbook.Worksheets(1).Range("B2").FormulaR1C1 = "9"
oWorkbook.Worksheets(1).Range("B3").FormulaR1C1 = "5"
oWorkbook.Worksheets(1).Range("B4").FormulaR1C1 = "1"
oWorkbook.Application.Quit()
End If
Next
I changed it to:
For Each oShape As Word.InlineShape In oDoc.InlineShapes
If oShape.HasChart And oShape.Range.Bookmarks.Item(1).Name = "ChartName" Then
Console.WriteLine("Updating ChartName")
Dim oWorkbook As Excel.Workbook
oWorkbook = oShape.Chart.ChartData.Workbook
oWorkbook.Worksheets(1).Range("B2").FormulaR1C1 = "9"
oWorkbook.Worksheets(1).Range("B3").FormulaR1C1 = "5"
oWorkbook.Worksheets(1).Range("B4").FormulaR1C1 = "1"
oShape.Chart.Refresh()
oWorkbook.Close(True)
End If
Next
Now it works
myDoc.SaveAs(fileNameAndPath)
Works for me in Word 2007
I can't find the syntax anywhere for setting a PowerPoint theme as the default theme using Excel VBA or PowerPoint (2010) VBA.
To clarify what I'm trying to do, the steps to do this mannually are: go to the design tab in PowerPoint, right click on the desired theme and select the "Set as Default" option. This process sets the default theme and slide master default.
The syntax below will set the theme (using Excel VBA) once but will not set the theme as the default. How do I set the theme as the new default?
Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible=True
Set PPPres = PPApp.Presentations.Add
PPPres.ApplyTemplate ("Location")
Much thanks to David for the ideas below but, unfortunately they do not work for my intended application. I am trying to create a macro that will set the default theme on open so that I can distribute that file to my org and control the slide template we are all working off of. This macro found HERE is very close but I cannot find syntax that will lock in the applied template. Thoughts?
Sub AutoOpen()
Dim ThemePath As String
Dim ThemeFile As String
Dim FullPath As String
ActivePresentation.PageSetup.SlideSize = ppSlideSizeOnScreen16x9
ThemeFile = "TestTemplate.potx"
ThemePath = "File Path"
FullPath = ThemePath + ThemeFile
On Error Resume Next
ActivePresentation.ApplyTemplate (FullPath)
If Err <> 0 Then
MsgBox (ThemeFile & " was not found in " & ThemePath)
End If
End Sub
I know this is 4 years too late, but I don't think that this question was ever adequately answered. In your code above you should set the following string variables to:
ThemeFile = "blank.potx" '(it has to be "blank" or else it won't work)
ThemePath = "C:\Users\" vba.environ("username") & "\AppData\Roaming\Microsoft\Templates"
http://youpresent.co.uk/set-the-default-template-when-powerpoint-starts/