VBA for wordfile

Tom.Jones

Well-known Member
Joined
Sep 20, 2011
Messages
525
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. Mobile
Hello,

I'm new here and I want ask you if is posible to make a button in excel and this button to open userform. In this userform I want to enter a date (dd.mm.yyyy) and pres a button to make wordfile named dd.mm.yyyy.docx. This file I want to be in same folder with my excel file.
I don't know if I was very clear.
If is posible can anyone help me wiyh this. I'm novice in VBA.
Thanks for any help.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Make_Word_Doc()<br><br>    <SPAN style="color:#007F00">' Add a reference to the MS-Word library:</SPAN><br>        <SPAN style="color:#007F00">' from the VBA menu, select Tools\References</SPAN><br>        <SPAN style="color:#007F00">' select 'Microsoft Word x.0 Object Library'</SPAN><br>        <br>    <SPAN style="color:#00007F">Dim</SPAN> WrdApp <SPAN style="color:#00007F">As</SPAN> Word.Application<br>    <SPAN style="color:#00007F">Dim</SPAN> WrdDoc <SPAN style="color:#00007F">As</SPAN> Word.Document<br>    <SPAN style="color:#00007F">Dim</SPAN> strWrdDate <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> strWrdFilename <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>        <br>Retry:<br>    strWrdDate = Application.InputBox(Prompt:="Enter a date as dd.mm.yyyyy ", _<br>                                      Title:="Date as Word.doc Filename", _<br>                                      Default:=Format(Date, "dd.mm.yyyy"), Type:=2)<br>    <SPAN style="color:#00007F">If</SPAN> strWrdDate = "False" <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>  <SPAN style="color:#007F00">'User canceled</SPAN><br>    <br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> strWrdDate <SPAN style="color:#00007F">Like</SPAN> "##.##.####" <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox "Please enter a date using the dd.mm.yyyy format. ", vbExclamation, "Invalid Date Format"<br>        <SPAN style="color:#00007F">GoTo</SPAN> Retry<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br>    strWrdFilename = ThisWorkbook.Path & Application.PathSeparator & strWrdDate & ".docx"<br>    <br>    <SPAN style="color:#00007F">Set</SPAN> WrdApp = CreateObject("Word.Application")<br>    <SPAN style="color:#007F00">'wrdApp.Visible = True</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> WrdDoc = WrdApp.Documents.Add <SPAN style="color:#007F00">' create a new document</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> WrdDoc<br>        .SaveAs strWrdFilename  <SPAN style="color:#007F00">' save the document</SPAN><br>        .Close                  <SPAN style="color:#007F00">' close the document</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    WrdApp.Quit                 <SPAN style="color:#007F00">' close the Word application</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> WrdDoc = <SPAN style="color:#00007F">Nothing</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> WrdApp = <SPAN style="color:#00007F">Nothing</SPAN><br>    <br>    MsgBox "Word file: " & strWrdFilename, vbInformation, "Word Document Created"<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,135
Members
452,890
Latest member
Nikhil Ramesh

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