- Remove From My Forums
-
Question
-
I have an MS Access file that opens a word template, populates it with data and saves it to a local share. The following code produces the above error:
Dim WordObj As Word.Application Set WordObj = CreateObject("Word.Application") WordObj.Visible = True WordObj.Activate WordObj.ShowMe WordObj.WindowState = wdWindowStateMaximize WordObj.Documents.Add(GetTemplatePath(strDocPath)) WordObj.ActiveDocument.SaveAs FileName:=FullDocName, FileFormat:=12 //this line produces the above error
I have tried many combinations of early / late binding with the word application object and always get the same result. The word document will open and the functions which insert text will run successfully, but the document will not be saved and if any further
editing is attempted Word will crash.I suspect that code isnt the problem; I have another identical workstation that is able to open and save the output document. What external factors could cause this?
Answers
-
What version of office do you have installed on your PC?
You can specify the version of excel you are creating the object.
From :
Set WordObj = CreateObject(«Word.Application»)
to :
Set WordObj = CreateObject(«Word.Application.12»)
You also may want to try using the following
WordObj.ActiveDocument.SaveAs FileName:=FullDocName, FileFormat:=acFileFormatAccess2007
Check the menu in access vba Tools — References Microsoft Word XX.X object Library. You may have to browse for a newer version of the object library. what sometimes hapPens if the macro was developed on a PC with 2003 the reference may be
pointing to the object library 11.0 while you need 12.0.Make sure the version of the object library is compatible with Word 2007. Version 12 is office 2007. The create object will automatically use the defualt version of office that is installed on your PC. If you have office 2010
installed you may need to specify a differnt version.Errors like -2147417851 (80010105) are usually caused by not having the priveledge to open the file. Make sure you can open the file by double clicking on the file and opening. I would aslo suspect you would get the error if your configuration
(like the reference) doesn’t support office 2007.
jdweng
-
Marked as answer by
Friday, February 25, 2011 9:50 AM
-
Marked as answer by
-
Wrong approach. You mix the application object with document object. Try this:
Dim appWord As New Word.Application
Dim objWord As Word.DocumentSet objWord = appWord.Documents.Add(GetTemplatePath(strDocPath))
appWord.visible = True
appWord.Activate
appWord.ShowMe
appWord.WindowState = wdWindowStateMaximizeappWord.ActiveDocument.SaveAs FileName:=FullDocName, FileFormat:=12
Greg
-
Marked as answer by
Bruce Song
Friday, February 25, 2011 9:50 AM
-
Marked as answer by
-
Hi Richard,
it’s interesting because this cide works fine for me with Office 2007:
Set wordobj = CreateObject("Word.Application") wordobj.Visible = True wordobj.Activate wordobj.ShowMe wordobj.WindowState = wdWindowStateMaximize wordobj.Documents.Add "********Desktoptest.docx" wordobj.ActiveDocument.SaveAs FileName:="********Desktoptest1", FileFormat:=12 wordobj.Quit Set wordobj = Nothing
But I’ve been facinf the situation when Excel automation hadn’t worked until setting the whole object «stairway».
Suggestions:
— Are you sure that exactly the last line causes an error?
— Does FullDocName have an extension part?
— Do you have more than one version of Office installed on this workstation?
Andrey V Artemyev | Saint-Petersburg, Russia
-
Marked as answer by
Bruce Song
Friday, February 25, 2011 9:50 AM
-
Marked as answer by
-
#1
This function has been working perfectly fine until now and nothing has changed. The OutMail.To function is failing and if I replace the Named Range with the string value of cell B11 it works. This fails everywhere this command uses a Named Range.
Rich (BB code):
Function Mail_workbook_Outlook(Recipient As String)
'Working in Excel 2000-2013
'Mail a copy of the ActiveWorkbook with another file name
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim wb1 As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim OutApp As Object
Dim OutMail As Object
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wb1 = ActiveWorkbook
'Make a copy of the file/Open it/Mail it/Delete it
'If you want to change the file name then change only TempFileName
TempFilePath = Environ$("temp") & ""
TempFileName = "Johns New Item Form " & Format(Now, "mm-dd-yy")
FileExtStr = "." & LCase(Right(wb1.Name, Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))
wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'On Error Resume Next
Select Case Recipient
Case "Buyer"
With OutMail
.To = Range("SF.BuyerEmail")
.cc = ""
.BCC = ""
.Subject = "Johns New Item Form " & Range("SF.SupplierContactName") & " " & Range("SF.SupplierInformation")(1) & " " & Format(Now(), "mm/dd/yyyy")
.Body = "Attention " & Range("SF.BuyerName") & " - Attached is the Johns New Item Form for your review."
.Attachments.Add TempFilePath & TempFileName & FileExtStr
.Send 'or use .Display
End With
Case "Supplier"
With OutMail
.To = Range("SF.SupplierEmail")
.cc = ""
.BCC = ""
.Subject = "Johns New Item Form " & Range("SF.SupplierContactName") & " " & Range("SF.SupplierInformation")(1) & " " & Format(Now(), "mm/dd/yyyy")
.Body = "Attention " & Range("SF.SupplierContactName") & " - Attached is the Johns New Item Form for your review."
.Attachments.Add TempFilePath & TempFileName & FileExtStr
.Send 'or use .Display
End With
Case "Final"
With OutMail
.To = "MDSM@Johns.com"
.cc = ""
.BCC = ""
.Subject = "Johns New Item Form " & Range("SF.BuyerName") & " " & Range("SF.SupplierInformation")(1) & " " & Format(Now(), "mm/dd/yyyy")
.Body = "Attention " & Range("SF.SupplierContactName") & " - Attached is the Johns New Item Form for your review."
.Attachments.Add TempFilePath & TempFileName & FileExtStr
.Send 'or use .Display
End With
Case Else
End
End Select
On Error GoTo 0
'Delete the file
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Function
Добрый день!
Прошу помощи.
При формировании письма в Lotus из Excel периодически выскакивает ошибка:
Run-time error ‘-2147417851 (80010105)’: Automation error
VBA ругается на строку:
Set uiDoc = uiWorkspace.EDITDOCUMENT(True, MailDoc)
В чем может быть проблема?
Код макроса прилагаю.
==========================
Sub Макрос_ОтправкаПисьма()
Dim Maildb As Object ‘The mail database
Dim UserName As String ‘The current users notes name
Dim MailDbName As String ‘The current users notes mail database name
Dim MailDoc As Object ‘The mail document itself
Dim AttachME As Object ‘The attachment richtextfile object
Dim Session As Object ‘The notes session
Dim EmbedObj As Object ‘The embedded object (Attachment)
Dim Subject As String ‘The subject string
Dim Attachment As String ‘The path to the attachemnt string
Dim Recipient As String ‘The Recipient string (or you could use the list)
Dim Recip(10) As Variant ‘The Recipient list
Dim BodyText As String ‘The body text
Dim SaveIt As Boolean ‘Save to sent mail
Dim WasOpen As Integer ‘Checking to see if the Mail DB was already
Dim uiDoc As Object
Dim uiWorkspace As Object
Dim docProfile As Variant
Dim strProfileEnableSignature As Variant
Dim CopyTo As String
Dim BlindCopyTo As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Subject = ТемаПисьма
Recipient = Email_Кому
CopyTo = Email_Копия
BlindCopyTo = Email_СкрытаяКопия
SaveIt = True
Set Session = CreateObject(«Notes.NotesSession»)
Set uiWorkspace = CreateObject(«Notes.NotesUIWorkspace»)
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) — InStr(1, UserName, » «))) & «.nsf»
Set Maildb = Session.GETDATABASE(«», MailDbName)
If Maildb.IsOpen = True Then
WasOpen = 1 ‘Already open for mail
Else
WasOpen = 0
Maildb.OPENMAIL ‘This will prompt you for password
End If
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = «Memo»
MailDoc.sendto = Recipient ‘Or use Racip(10) for multiple
MailDoc.CopyTo = CopyTo
MailDoc.BlindCopyTo = BlindCopyTo
MailDoc.Subject = Subject
MailDoc.Body = ТекстПисьма
‘MailDoc.SAVEMESSAGEONDRAFTS = SaveIt
Set AttachME = MailDoc.CREATERICHTEXTITEM(«Attachment»)
Set EmbedObj = AttachME.EMBEDOBJECT(1454, «», ВложениеПисьма)
‘MailDoc.PostedDate = Now() ‘Gets the mail to appear in the sent items folder
‘Set uiDoc = uiWorkspace.EDITDOCUMENT(True, MailDoc)
Set docProfile = Maildb.GETPROFILEDOCUMENT(«CalendarProfile»)
strProfileEnableSignature = docProfile.GETITEMVALUE(«EnableSignature»)(0)
If strProfileEnableSignature = «1» Then
docProfile.EnableSignature = «»
Call docProfile.Save(True, False)
End If
Set uiDoc = uiWorkspace.EDITDOCUMENT(True, MailDoc)
If strProfileEnableSignature = «1» Then
docProfile.EnableSignature = «1»
Call docProfile.Save(True, False)
End If
‘MailDoc.SEND 0, Recipient // if you want to send
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set EmbedObj = Nothing
Set uiDoc = Nothing
If WasOpen = 1 Then
Set Session = Nothing
ElseIf WasOpen = 0 Then
Set Session = Nothing
End If
Dim Msg, Style, Title
‘Msg = «E-mail has been sent to » & Recipient & Chr(13) & Chr(10) & Chr(13) & Chr(10) & «Press OK to continue.»
Style = vbOKOnly + vbInformation
Title = «Open Issues List»
‘Response = MsgBox(Msg, Style, Title, Help, Ctxt)
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Run-time error ‘ 2147417851 (80010105) Method’To’ of object’_MailItem’failed
Hello Forum!
When I am running this code on a Windows XP platform whit Outlook2010 and Access2010 the code are working,
when I am running the same code on a Windows10 platform with Outlook2010 and Access2010 the code are NOT working, it stops at
.To = Me.Emailkontaktpersonand gives this message » Run-time error ‘ 2147417851 (80010105) Method’To’ of object’_MailItem’failed «
Do Forum have any suggestion to what are causing this???
Private Sub Kommandoknap35_Click()
Dim DocName As String
Dim objOutlook As Object
Dim objOutLookMsg As Object
Dim strBody As String
Dim DocPath As String
Dim rst As DAO.Recordset‘Me.txtBillingEmail is a text field on the invoice form that has the billing email
‘On Error GoTo Kommandoknap35_Click_ErrorIf Me.Emailkontaktperson = «No billing email on file.» Then
‘When a customer has no email the system inserts the text
‘»No billing email on file.»
MsgBox «No billing email on file.», vbInformation, «Can’t Email»
Exit Sub
End If‘The DocName is the name of the invoice report
DocName = «RapTilbud»
‘First, we open the report to the screen using the invoice #
DoCmd.OpenReport «RapTilbud», acViewPreview, , «[Ordrenr]=» & Me.Ordrenr‘DocPath stores the complete path of the PDF
‘DocPath = CurrentProject.path & «Fakturanr» & » » & Me.Ordrenr & » » & Me.Kundenavn & » .pdf»
DocPath = «C:UsersCarstenDesktopTilbud2doo» & «Tilbud nr» & » » & Me.Ordrenr & » » & Me.Kundenavn & «.pdf»‘Delete pdf if it exists
If Dir(DocPath) <> «» Then
Kill DocPath
End If‘Second, we save the invoice to the directory where the program is launched from
‘we use the invoice number in the name of the file
‘DoCmd.OutputTo acOutputReport, DocName, acFormatPDF, CurrentProject.path & «Fakturanr» & » » & Me.Ordrenr & » » & Me.Kundenavn & » .pdf», False
DoCmd.OutputTo acOutputReport, DocName, acFormatPDF, «C:UsersCarstenDesktopTilbud2doo» & «Tilbud nr» & » » & Me.Ordrenr & » » & Me.Kundenavn & «.pdf», False
‘Close the report since it’s no longer needed
DoCmd.Close acReport, DocName‘rst is opened to the options table that holds the subject and body templates
Set rst = CurrentDb.OpenRecordset(«Select * from Masterdata»)
‘objOutlook will be used to refence Outlook in the program
‘I recommend Outlook is open while the code is executing
Set objOutlook = CreateObject(«Outlook.Application»)
‘Create a new message:
Set objOutLookMsg = objOutlook.CreateItem(0)
With objOutLookMsg
‘Use the email field on the invoice for the To field
.To = Me.Emailkontaktperson
‘Optional: copy another email address that will receive a copy of the pdf
‘.CC = «any@what_ever.com”»
I had a similar problem, and it bugged the heck out of me. My eventual fix (workaround) was using a variable, which you wouldn’t think would matter. Declare a string variable and then populate and use it.
Dim strEmail As String
…
strEmail = Me.Emailkontaktperson
.To = strEmail
Resolved — Thank You very much
Originally Posted by pbaldy
![]()
I had a similar problem, and it bugged the heck out of me. My eventual fix (workaround) was using a variable, which you wouldn’t think would matter. Declare a string variable and then populate and use it.
Dim strEmail As String
…
strEmail = Me.Emailkontaktperson
.To = strEmailResolved thank you very much!!!
Happy to help and welcome to the site by the way! I stumped some great minds with that before stumbling on the answer while experimenting.
Worked for me as well, Thanks!
Originally Posted by pbaldy
![]()
I had a similar problem, and it bugged the heck out of me. My eventual fix (workaround) was using a variable, which you wouldn’t think would matter. Declare a string variable and then populate and use it.
Dim strEmail As String
…
strEmail = Me.Emailkontaktperson
.To = strEmail————————
I was having the same problem, your example work great for me, Thanks!
I’m glad it helped you! I never got a definitive answer. It was speculated that the newer OS versions were trying to pass the object itself rather than the value within the object, and declaring a variable forced the result to be the desired string. Once I got it solved (or more accurately worked around) I stopped researching.
OS was my speculation because the only users I had that experienced the problem were those that had been upgraded. I had a client that had the same issue: code that had been working fine suddenly having this error when users were upgraded to Win 10. It could certainly have been something else. In my case, once I sorted it out it was on to the next crisis, so I didn’t go back and try to isolate the culprit.
-
02-10-2016, 06:30 AM
#1
Registered User
Run-time error ‘-2147417851 (80010105)’: Method ‘Paste’ of object ‘Shapes’ failed
Hi all,
I have posted about this before and also tried all different ways of fixing the problem but am still experiencing this error message. My macro takes information from a CSV file and pastes it into a pre-determined workbook. It them goes about populating charts, sending these to a pre-determined Powerpoint template.
Since updating from Excel 2010 to Excel 2013 and Excel 2013(365), I’ve been experiencing many issues with this inherited code. I initially tried to find if this update was the cause of this particular problem but can find nothing to say that it is — although this error has now arisen for both offices using different documents containing the code.
The line of code causing the bug is highlighted in red below (this is the first subroutine in which it occurs — the code has always used this line of code for pasting). I have edited this line to also be PPSlide.Shapes.Paste.Select to see if that was an issue, but have not used any PasteSpecial, etc functions.
Any help anyone can give would be truly appreciated — also happy to display more of the code if needed.
Thanks!
-
02-10-2016, 06:38 AM
#2
Re: Run-time error ‘-2147417851 (80010105)’: Method ‘Paste’ of object ‘Shapes’ failed
Wild guessing here… Have you tried replacing
PPSlide.Shapes.Paste
with
PPSlide.Paste.. and don’t forget to have fun!
Bogdan.mark SOLVED and
Add Reputation if my answer pleases you
-
03-03-2016, 07:26 AM
#3
Registered User
Re: Run-time error ‘-2147417851 (80010105)’: Method ‘Paste’ of object ‘Shapes’ failed
Originally Posted by bulina2k
Wild guessing here… Have you tried replacing
PPSlide.Shapes.Paste
with
PPSlide.PasteI get «compile error: method or data member not found» when changing to this… Hmm…
Run-time error ‘-2147417851 (80010105)’
(OP)
13 Dec 06 08:41
Morning all,
I am having difficulty opening a Word document from within a VB6 Project. The error I receive is:
Run-time error ‘-2147417851 (80010105)’
Automation error. The server threw an exception.
I am relatively new to VB and have searched and tried suggestions with no success. I have included the code below for your review. This activity is for a government project and the need is quite urgent. Any help that you may be able to provide would be most sincerely appreciated.
Note: wdApp is defined in an initialization module at
program start.
A variable is used for the table name as there
could be several processed by this module.
Sub ExceltoWord(strXlTbl As String)
Dim strXLFilePath As String
strXLFilePath = «C:PCARSS_v1.0OutputData» & strXlTbl
‘*** Open file in WORD and replace tab delimeter with |
Set wdApp = New Word.Application
wdApp.Visible = False
wdApp.Documents.Open FileName:=strXLFilePath, _
ConfirmConversions:=False, _
ReadOnly:=False, _
AddToRecentFiles:=False, _
PasswordDocument:=»», _
PasswordTemplate:=»», _
Revert:=False, _
WritePasswordDocument:=»», _
WritePasswordTemplate:=»», _
Format:=wdOpenFormatAuto
‘*** Open text file and select complete document
wdApp.Selection.WholeStory
wdApp.Selection.Find.ClearFormatting
wdApp.Selection.Find.Replacement.ClearFormatting
‘*** Clear any «s
With wdApp.Selection.Find
.Text = «»»»
.Replacement.Text = «»
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wdApp.Selection.Find.Execute Replace:=wdReplaceAll
‘*** Clear any ?’s
With wdApp.Selection.Find
.Text = «?»
.Replacement.Text = «»
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wdApp.Selection.Find.Execute Replace:=wdReplaceAll
‘*** Replace tab delimeter with | delimiter
With wdApp.Selection.Find
.Text = «^t»
.Replacement.Text = «|»
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wdApp.Selection.Find.Execute Replace:=wdReplaceAll
‘*** Save document as .txt
wdApp.ActiveDocument.SaveAs FileName:=strXLFilePath, _
FileFormat:=wdFormatText, _
LockComments:=False, _
Password:=»», _
AddToRecentFiles:=True, _
WritePassword:=»», _
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, _
SaveFormsData:=False, _
SaveAsAOCELetter:=False
wdApp.ActiveDocument.Close (wdSaveChanges)
wdApp.Application.Quit
Set wdApp = Nothing
End Sub