Hi All,
I made a model for our department and part of this model is the option to generate, from excel, a word document with data from excel and then save it to a shared drive.
Now the strange thing that happend suddenly that 1 user gets a Run-time error '13' : Type mismatch.
Up till now no other users (including me) are getting this error. For me it just works fine.
Can anybody tell me what is going on here? In the past she was also able to generate the word file.
And just to let you know, yes she still has read/write authorization on that shared drive.
Here is the code. The line which generates the error is to the bottom of the code and is the line which starts with "objWord.ActiveDocument.SaveAs Filename:="P:\Finance\....."
Sub worddoc()
Dim a As Integer
Dim objWord As Object
Dim bookmarks As Excel.Range
Dim ws As Worksheet
warning = Sheet1.Range("N9").Value
x = Sheet1.Range("M10").Value
account = Sheet1.Range("M6").Value
accountn = Sheet1.Range("N6").Value
datum = Sheet6.Range("B8").Value
maand = Sheet6.Range("D8").Value
srange = "P:\Finance\CC and treasury\TEMPLATES\STATEMENTS\WordFiles\"
If warning = True Then
If x = "X" Then
a = MsgBox("You did not press 'Generate' again!" & vbNewLine & vbNewLine & "If you did choose another account you will get" & vbNewLine & "a mismatch between name and data when the file gets saved!" & vbNewLine & vbNewLine & "Are you sure you want to re-process like this?", vbYesNo + vbExclamation, "WARNING!")
If a = vbYes Then GoTo Verder
If a = vbNo Then Exit Sub
End If
Else
End If
Verder:
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "P:\Finance\CC and treasury\TEMPLATES\STATEMENTS\WordFiles\Template\Template.docx"
With objWord.ActiveDocument
.bookmarks("Text1").Range.Text = Sheet6.Range("A1").Value
.bookmarks("Text2").Range.Text = Sheet6.Range("A2").Value
.bookmarks("Text3").Range.Text = Sheet6.Range("A3").Value
.bookmarks("Text4").Range.Text = Sheet6.Range("A4").Value
.bookmarks("Text5").Range.Text = Sheet6.Range("A5").Value
.bookmarks("Text6").Range.Text = Sheet6.Range("A6").Value
.bookmarks("Text7").Range.Text = Sheet6.Range("A7").Value
.bookmarks("Text8").Range.Text = Sheet6.Range("B8").Value
.bookmarks("Text8").Range.Text = Sheet6.Range("A8").Value
.bookmarks("Text9").Range.Text = Sheet6.Range("A9").Value
.bookmarks("Text10").Range.Text = Sheet6.Range("A10").Value
.bookmarks("Text12").Range.Text = Sheet6.Range("A11").Value
.bookmarks("Text13").Range.Text = Sheet6.Range("A12").Value
.bookmarks("Text14").Range.Text = Sheet6.Range("A13").Value
.bookmarks("Text15").Range.Text = Sheet6.Range("A14").Value
.bookmarks("Text16").Range.Text = Sheet6.Range("A15").Value
End With
objWord.ActiveDocument.bookmarks("Text11").Select
lrow = Sheet1.Range("B" & Rows.Count).End(xlUp).Row
Sheet1.Range("B5:K" & lrow).Copy
objWord.Selection.Paste
Application.CutCopyMode = False
objWord.ActiveDocument.SaveAs Filename:="P:\Finance\CC and treasury\TEMPLATES\STATEMENTS\WordFiles\" & maand & "\" & account & "-" & accountn & " " & datum & ".docx"
objWord.Documents.Close
objWord.Quit
Set objWord = Nothing
notification = Sheet1.Range("N11").Value
If notification = True Then
MsgBox "Document '" & account & "-" & accountn & " " & datum & ".docx'" & vbNewLine & vbNewLine & "saved to " & srange & maand, vbOKOnly + vbInformation, "Word file created"
Else
End If
Sheet1.Range("M10") = "X"
Range("A1").Select
End Sub
Thanks!
Bookmarks