Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: office 2007 macro help

22 Oct 2016   #1

windows 7 premium 32 bit
office 2007 macro help

I am trying insert picture in active document and then either mail it as pdf or print directly to printer.

I have written following code which works ok if I step through it in code window. but on executing directly from document direct print option doesn't send the document to printer quene though printer does get activated in task bar but shows 0 document to print.

Can somebody guide me ?

code is as follows

Sub printdocument()
Dim filename As String

With Selection.Find
.Text = "xxxxxxxx"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With

Selection.Collapse Direction:=wdCollapseStart

With Selection.InlineShapes
.AddPicture filename:="C:\xx.png", LinkToFile:=False, _
SaveWithDocument:=True, Range:=Selection.Range
End With
Dim YesOrNoAnswerToMessageBox As String
Dim QuestionToMessageBox As String
Dim mailaddress As String

QuestionToMessageBox = "want to send mail?"

YesOrNoAnswerToMessageBox = MsgBox(QuestionToMessageBox, vbYesNo, "VBA Expert or Not")
If YesOrNoAnswerToMessageBox = vbNo Then

ActiveDocument.PrintOut Range:=wdPrintCurrentPage

End If
If YesOrNoAnswerToMessageBox = vbYes Then
filename = InputBox("yyyy")
Dim FName As String
FName = "d:\zzzz\" & filename & ".pdf"
ActiveDocument.SaveAs ("D:\zzzz\") & filename
myfile1 = ActiveDocument.Name
intPos = InStrRev(myfile1, ".")
If intPos > 0 Then
myfile = Left(myfile1, intPos - 1)
End If

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
Replace(ActiveDocument.FullName, ".docx", ".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _
wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False

mailaddress = InputBox("")
FName = "d:\zzzz\" & myfile & ".pdf"
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = mailaddress

.Subject = myfile

oItem.Attachments.Add FName


End With
End If

Application.Quit SaveChanges:=wdDoNotSaveChanges

End Sub

My System SpecsSystem Spec

 office 2007 macro help

Thread Tools

Similar help and support threads
Thread Forum
MS Office 2010 - Word Macro
I am a novice at this and I have searched and searched over the last week trying to figure out a fix to this. I'm trying to create a Word Macro to remove time from date: This occurs in 4 different cells. Cell in Word shows: 05/04/2016 10:00:00 I just need the date to show without the...
Microsoft Office
When I open a Word 2007 document, a Visual Basic editing macro opens
When I open any existing (not when I create a new) Word 2007 document (in this case one entitled “Word 2007 test document”), I am greeted with the following: attached image VB01 When I click on I get: attached image VB02  
Microsoft Office
Excel 2007 (MS Office 2007 enterprise)
I recently formatted my HD and reinstalled MS Office Enterprise 2007, I last used MS Excel on the 08/06/2014 without a problem, today I go to use my Excel spreadsheet and for some weird reason it wants to roundup my cells. I have cleared the cells formatted the number but it still keeps on...
Microsoft Office
File Validation from Office 2010 to Office 2003 and Office 2007
File Validation from Office 2010 to Office 2003 and Office 2007 - Softpedia
Word 2007 Macro Alert Since Win7 upgrade
Word 2007 displays several Macro warnings when I open a simple Word document that contains no macros what so ever. The .Doc is just a table of four columns with data. This same .DOC opened without any problem while running Vista64. All I did was an upgrade. Word was installed during Vista64...
Microsoft Office

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 10:02.
Twitter Facebook Google+