Free Microsoft Excel 2013
Quick Reference
Free Microsoft 2013 Quick Reference Guide

Free Microsoft Excel 2013 Quick Reference

Command button to open a word document Results

Hi,

I am using Excel 2002 currently I have workbook that has 6 different types
of worksheet all of the worksheet consist of data input and formulas except
for 1 worksheet. The examiners are auditing our clients inventory. The one
worksheet (Client letter) that the examiners use is sort of predefined
letter where they typed up information The letter can vary from industires,
Manufacturing, Retail, etc. Basily we copy and paste the template from the
bottom of the Client's letter. The problem with that is Excel is not MS
Word. I am wondering what is the best way I tackle this problem? I have
about 5 different letter types and I would like to keep everything in Excel.
I believe I can add a Word control, but how do I add the various industries.
Do I need to have 5 different command buttons to open up Word?. Any tips or
help or website to go for an example will be appreciated. Thank you.

Hi,

I would like to write Macro/VBA code so that when I click my Command button, it will open up a Word document The word document will open from a URL rather than a network folder.

Any help you could provide would be great thank you.

Hi

I am new to using VBA and would be grateful for advice. I am trying to put a simple command button on a spreadsheet that would open a word document that I want to use for mail-merge purposes. I am using the 2000 versions of both Word & Excel.

I have tried using the following code (picked from a number of advice sites!) but I get an error message "Automation error: The server threw an exception" when trying to run the code. Any help to get it working would be greatly appreciated!

Sub Button1_Click()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:LetterTemplate.doc")
End Sub

Many thanks

Happy New Year!

What is going on?

My scenario:
I have an Excel Userform with 2 command buttons.
Commandbutton 1: opens an excel file (this works)
Commandbutton 2: NEEDS to open a word document (problem)

How can I open a word document from this Excel Userform?
Does Excel open Excel related files only?

This is the code to open the Excel file: (this works)
Private Sub cmd1_Click()
ChDir "J:Myrna"
Workbooks.Open Filename:="J:Myrnaopenexcel-1.xls"
End Sub

This is the code to open the word file: (problem)
Private Sub cmd2_Click()
ChDir "J:Myrna"
Workbooks.Open Filename:="J:Myrnaopenword-1.doc"
End Sub
>>>ERROR MESSAGE: runtime error: file format is not valid

Thanks in advacnce for your help & have a happy day!

*** Sent via Developersdex http://www.developersdex.com ***

I'm trying to copy some cells from a excel sheet to a word document, by using the Command Button in word.
The problem I'm facing is that with my code, I can only copy one cell from excel into word.
Now to my question, how do I add multiple/different cells (columns and rows) into the word document?
First I created a excel document named autoWordfile and then I created a word document with an Command Button (ActiveX control).
As Reference for the project I chose the Microsoft Excel 14 Object Library.

This is how my code look like:

	VB:
	
 CommandButton1_Click() 
    Dim objExcel As New Excel.Application 
    Dim wb As Excel.Workbook 
     
    Set wb = objExcel.Workbooks.Open("C:UsersAAAWasteautoWordfile") 
     
    Selection.TypeText wb.Sheets("Sheet1").Cells(1, 1) 
     
    wb.Close 
     
    Set wb = Nothing 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
Now my second idea which is what I want to achieve.
I'm going to create a questionnaire document in excel that automatically transfer relevant information from excel to word. In other words, transfer the value adding information from the more informative excel document. I would desire to transfer information from question 1 in excel to it's relating Q1"answering box" in word.
Does anyone have any idea how to perform this?

Hi,

I have a spreadsheet that contains command buttons. These buttons open other sheets within the workbook. Is it possible to create a command button that will open a word document. If that can't be done is there a way of navigating to the specific folder by clicking a command button.

Many thanks.

I am having a excel worksheet.
I am having a command button in the work sheet.

When I click the command button, a word document should open "abc.doc"

The word doc is in the following path

c:krishnaabc.doc

Please help me how to perform this task

Krishnakanth
Software Engineer

Hi all,
I need some code that will allow me to open an Excel Workbook from a
command button I have placed on my Userform.

My Userform form has various command buttons that allow me to open Word
documents, and I need the equivalent that will allow me to now open
Excel files as well.

This is an example of the code that sits under a command button that
will allow me to open a Word document.

Private Sub cmdShowDocument1_Click()
Call OpenFile("C:Document1.doc")
End Sub

.... and this is the called function.

Public Sub OpenFile(ByVal File_Name As String)
Dim OpenFileVar
OpenFileVar = ShellExecute(0&, "open", File_Name, vbNullString,
vbNullString, 1)
End Sub

I need something similar that will allow me to open Excel Workbooks.

Thanks very much for your help with this.

Regards
Karen

Hi all,

I need some code that will allow me to open an Excel Workbook from a
command button I have placed on my Userform.

My Userform form has various command buttons that allow me to open Word
documents, and I need the equivalent that will allow me to now open
Excel files as well.

This is an example of the code that sits under a command button that
will allow me to open a Word document.

Private Sub cmdShowDocument1_Click()
Call OpenFile("C:Document1.doc")
End Sub

.... and this is the called function.

Public Sub OpenFile(ByVal File_Name As String)
Dim OpenFileVar
OpenFileVar = ShellExecute(0&, "open", File_Name, vbNullString,
vbNullString, 1)
End Sub

I need something similar that will allow me to open Excel Workbooks.

Thanks very much for your help with this.

Regards
Karen

Hi,
Pretty new to the whole VBA world but have figured out what I want to happen from most of the posts on this and other forums... I'm stuck on one point though.

This is what I've done:
I have an excel spreadsheet which is pretty rudimentary. The spreadsheet is set up like a checklist (for users to enter data in to or utilise the data/text already contained) with corresponding cells filled with paragraph text. In the spreadsheet I've created individual command buttons next to checkpoint with individual code/macro's associated to copy the paragraph text in an individual excel cell and paste it in to a word document template letter I have created.

This is what I want to have happen:
Essentially the user needs to be able to click as many of the command buttons in the spreadsheet as needs be and they must auto paste over to the correct area in the word document. I have lots of bookmarks set up in the word document and I can get it to paste over the data from the cells beautifully but it will only paste it where my cursor is sitting on the word document or it dumps it at the top if it opens the word document using the macro.

This is my code currently but I'm unsure how to amend it to point the paste to the correct bookmark in the word document:
Private Sub CommandButton1_Click()
Dim appwd As Object
On Error GoTo notloaded
Set appwd = GetObject(, "Word.Application")
notloaded:
If Err.Number = 429 Then
Set appwd = CreateObject("Word.Application")
End If
appwd.Visible = True
On Error GoTo 0
With appwd
.Documents.Open "C:UsersAndreaDocumentsWorkDAP not accepted v1.doc" 'must look for not accepted letter in correct drive '
Range("E6:F6").Copy
.Selection.Paste
'******Approved forms button'
End With
End Sub

Can anyone help?

I've written some code that is activated by a command button in Excel and opens a Word .doc file. The code then performs a mail merge using data in the spreadsheet and saves the result to a user-defined path and file name. The code then automatically closes the opened Word documents. Everything works fine on the first try and if I don't close the Word application itself (just close the Word files). However, as soon as I close the Word application, the code errors out when I try to run the macro again. In fact I can't get the macro to run until I close everything and start over.

Is there something I'm missing in the way I'm handling the Word app from Excel that causes this error?

The code specific to Word is included below:

Dim wdDoc As Object

On Error Resume Next
Set WApp = GetObject(, "Word.Application")
If Err.Number 0 Then 'Word isn't already running
Set WApp = CreateObject("Word.Application")
End If

Set wdDoc = WApp.Documents.Open("C:Template.doc")
wdDoc.select

'THE NEXT OPERATION IS WHERE I GET THE ERROR
ActiveDocument.MailMerge.OpenDataSource Name:= _
SheetPath _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=SheetPath;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry " _
, SQLStatement:="SELECT * FROM `Requirements$`", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = RecordRow
.LastRecord = RecordRow
End With
.Execute Pause:=False
End With

On Error GoTo 0

'SAVE NEW WORD FILE
With Dialogs(wdDialogFileSaveAs)
If .Display Then
FinalSaveFile = WordBasic.filenameinfo$(.Name, 3)
Else
End If
End With

ActiveDocument.SaveAs FileName:=FinalSaveFile, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False

Documents.Close savechanges:=False
WApp.quit

Hello to you all,

I am looking for some help with VB as I am a new user.

I have an excel spreadsheet with a command button "Private Sub CommandButton1_Click()" (but it can be routed to a standard macro if required), and what I want to happen when I click it is to open a Word file....

Filepath
"K:xxxxxxxxxWordFilename.docm"

Then I want it to search through that file and find the text "TextSearch" and replace it with "TextReplace".

I am using office 2007 and with macro enabled documents. How are you able to do this?

If anyone has any tips on Word macros being used in excel I would also appreciate any advice.

I would like to be able to open a word document with a command button on a userform in Excel. how would i go about doing this, any help would be great thanks,
Thanks, Dereck Houge

Hi Everyone,

I have a code which currently moves one column from the workbook to a word document called test which has an empty table in it.

I would like to change this so that when the user clicks the command button a userform appears, he then enteres a number into a text box and clicks OK.

The code needs to search the sheet1 for that number, lets say the reference numbers will be in columnB in sheet1.
Lets say the user entered 30, and that number appeared in cell B40, it would then move the data from that row, columnE (so cell E40 down until it found a blank cell, columnF (cell F40) down until it found the word 'total cost', and columnG (cell G40) down until it found a blank cell.

This information will be copied accross the the table in the 'test' word document.

heres my current code:
Sub ExportData()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdCell As Word.Cell
Dim i As Long
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim rnData As Range
Dim vaData As Variant


Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets("Sheet1")

With wsSheet
Set rnData = .Range("A1:E10")
End With

'Add the values in the range to a one-dimensional variant-array.
vaData = rnData.Value

'Here we instantiate the new object.
Set wdApp = New Word.Application

'Here the target document resides in the same folder as the workbook.
Set wdDoc = wdApp.Documents.Open(ThisWorkbook.Path & "Test.doc")

'Import data to the first table and in the first column of a table in Microsoft Word.
For Each wdCell In wdDoc.Tables(1).Columns(2).Cells
i = i + 1
wdCell.Range.Text = vaData(i, 2)
Next wdCell

'Save and close the document.
With wdDoc
.Save
.Close
End With

'Close the hidden instance of Microsoft Word.
wdApp.Quit

'Release the external variables from the memory
Set wdDoc = Nothing
Set wdApp = Nothing
MsgBox "The data has been transfered to Test.doc, vbInformation"
End Sub
Any help would be really aprreciated

Is it possible in VBA to copy named range data and paste it in to new word document?, I intend using a command button to start the code where for arguments sake Range("A1") will have a name selected from a list which will be the name of the named range, on click of the button copy and paste the named range data (values only!) in to a newly opened word document, it doesnt matter if it is pasted in to the default position (where the cursor starts flashing) when you first open word.

Any ideas?

Regards,
Simon

Hi all,

I have a Userform with various command buttons in place. What I'm
trying to do is allow users to be able to open various Word documents
when they click on these command buttons via the use of hyperlinks
embedded within the click event of each command button.

So if they click on one of the command buttons it opens one Word
document, and if they click another, it opens the second Word document
etc. etc.

It would be ideal to have the Userform to always remain displayed, so
the documents open in the background, and the Userform always has the
focus... then once the desired documents are all opened they can then
close the Userform if they wish.

Thanks for your help

Karen

Hi: I have a workbook comprised of approximately 150 worksheets that each function as a template for data input into a mainframe application. A user selects a button on the "Main Menu" worksheet and a macro copies text from one of the 150 templates onto a "blank" template worksheet where the text is edited prior to being pasted into a mainframe application. The mainframe application used to have a limit of 12 lines by 72 characters so I set-up the templates with the same restrictions. There is no longer a restriction on pasting into the mainframe, so for user friendliness, I'd rather use Word as the editor versus Excel.

So, my idea is to continue using Excel as the place where the templates reside, but instead of copying them into a blank template in Excel, I want to paste them into a blank Word document. The following code copies the text from the correspoding template and then activates Word. From here, I am interested in knowing how to accomplish two things:

1) How to open a specific document within Word to act as the "blank" template where text will be pasted into.

2) How to automatically trigger the "Paste Special" command in Word to past the text in unformatted unicode text.

Here's what I have so far. i.e. I know how to copy the text and open Word. I'm stuck from there.

I'm also open to other strategy suggestions. (Please note that I considered using Excel as the editor versus Word by simply pasting all the text into a single cell. It works OK until you start pasting very large text blocks.)

Any help is sincerely appreciated.

Thanks in adavance for any responses.

Dave

Sub AmalgamationMandatory()

Sheets("AmalgamationMandatory").Select
Range("B2:B201").Select
Selection.Copy
Application.ActivateMicrosoftApp xlMicrosoftWord

End Sub

Hi everyone,

My code so far allows me to enter data into an excel file, and then when you click a button, it opens up a word template and fills in the data in specific places based on the data in the excel file. I would like a copy of this file (while not overwritting the original) to be saved in a certian location on the C Drive. (i wish to be able to chose the location). Does anybody know how to add this command?

Thank you in advanced

here is my code so far

	VB:
	
 OpenWord_Click() 
    Set word = CreateObject("word.application") 
    word.documents.Open Filename:="[URL="file://demchp9901xsto.ww002.siemens.netz002xwrk$My"]location of template
document[/URL].doc" 
    word.Visible = True 
     
    Dim i As Integer 
    Dim x As Integer 
    Dim t As Integer 
    i = 9 
    t = 3 
     
    MyCount1 = Application.CountA(Range("A:A")) 
     
    Range("A9").Select 
     
    Set wordtab = word.ActiveDocument.tables(3) 
    For x = 1 To (MyCount1) 
        Kst = Cells(i, 1).Value 
        i = i + 1 
        word.Visible = True 
        wordtab.Cell(t, 1).Select 
        t = t + 1 
        word.Selection.Text = Kst 
    Next 
     
    Date = Cells(1, 2) 
    Set wordtab = word.ActiveDocument.tables(1) 
    wordtab.Cell(1, 3).Select 
    word.Selection.Text = Date 
     
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines


Hi all,

I am creating a workbook that will be opened for 2 purposes.

1) By a button on a word-document to create a new documentnumber

A macro create_number() in Workbook_Open() will create a new document number at the last line of sheet1 and copy some field data (user,subject,...)from the word document to the last line in the sheet.

2) Open the workbook from explorer

to have an overview of the created numbers.

PROBLEM

When i open the workbook from the explorer to have an overview, the create_number() procedure will also start.
Is there a way to avoid this.
With the old msdos batch-files you could work with arguments on the command line to start up a batch file.

Is is possible to do this with excel files.

for example:
Opening book1.xls
or
Opening book1.xls number

in the create_number() procedure i could check an argument was given and exit the sub immediatly.


	VB:
	
 create_number() 
    If argument = "number" Then 
         ' code to create number
    Else 
        exit Sub 
        endif 
    End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
does someone know a solution for my problem.

Thanks in advance
KHautekier.

I created folder on my desktop to hold various documents. I have master excel document which contains forms and command buttons that open documents from same folder. Is there a way to change code instead of having full file path to specify current directory. I'm worried that if I move this folder to another location then my open file button will not work since location is changed.
Also when I open with command button word document, I have a button on word document to close. I can close document but word application is still active. Can I close word application with the document at the sam time. This is the code I'm using: "ActiveWindow.Close"

Thanks for any help.


No luck finding an answer? You could always try Google.