VBA code runs and creates new file with a format of file and not word doc!!

sashapixie

Board Regular
Joined
Aug 29, 2013
Messages
71
Office Version
  1. 365
Platform
  1. Windows
Hello There,

I have the following vba written in my access 2013 database:

Private Sub CmbMobileReceipt_Click()

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim sEmployeeFullName As String

sEmployeeFullName = Full_Name
sMobileNumber = Mobile_Phone

'Open Word
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True

'Print Employee handbook receipts
MobileReceipt = CurrentProject.Path & "\Mobile Phone acceptance letter"
Set wrdDoc = wrdApp.Documents.Open(MobileReceipt)
With wrdApp.ActiveDocument.Bookmarks

.Item("EmployeeFullName").Range.Text = sEmployeeFullName
.Item("MobileNumber").Range.Text = sMobileNumber

wrdApp.ActiveDocument.PrintOut
wrdApp.ActiveDocument.Close


'Close Word
wrdApp.Application.Quit

'Clean up code
Set wrdApp = Nothing

End With
End Sub

When I run this code a file appears in my folder location with the same document name but the file type is a file and not a word document, when I run the code again it always opens this file, does anyone know why this is happening or how I can delete the file?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I think you are missing the file extension in your MobileReceipt variable - doc or docx. You probably don't see the extension in windows explorer but it is supposed to have an extension. Right click on the file, properties and see the file extension and add to the variable like below.

Code:
[COLOR=#333333]MobileReceipt = CurrentProject.Path & "\Mobile Phone acceptance letter.docx"[/COLOR]
 
Upvote 0
Hello Smozgur,

Thank you, I have added the doc to the end of the file path and this has fixed my issue. :)
 
Upvote 0

Forum statistics

Threads
1,216,477
Messages
6,130,879
Members
449,603
Latest member
dizze90

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top