Free Microsoft Excel 2013 Quick Reference

Open Word file form Excel using VBA and file path

Open Word file form Excel using VBA and file path

I’m using an excel spreadsheet as an Add-in menu. Also in the same workbook is a sheet with the menu structure and paths to other excel files.

It’s working great using this:

Private Sub GetXLWorkbook()
    Workbooks.Open CommandBars.ActionControl.Parameter, , True
    Exit Sub
End Sub
Now I’m trying make it open word files as well using this:

Sub GetWordWorkbook()
    Dim wordApp As Object
    Dim wordDoc As Object
    Set wordApp = CreateObject("Word.application")
    wordApp.visible = True
    Set wordDoc = wordApp.Documents.Open("C:Example.doc") 
End Sub
Opening word files does work if I run it manually but it does not work if I write the path in my excel menu? There is a problem with this path line:

Hope someone can help.

KR Peter


Post your answer or comment

comments powered by Disqus
Ok, I'm trying to open and update a MS Word document from Excel using
VBA, but everytime I try to open it, it loads as a Read Only Document,
giving me the message that this file is locked for use by myself, and
thus not allowing me to save it. I'm using this code to open it (the
SendKeys does not appear to make any difference to this message):

Sub Button13_Click()
Dim wdApp As Object
Dim wdDoc As Object
Dim sFname As String

sFname = "R:SALESQuote GeneratorsQuotes2 Pass Tray2 Pass Tray
Quote.doc" 'File Location

If sFname = "R:SALESQuote GeneratorsQuotes2 Pass Tray2 Pass
Tray Quote.doc" Then

Set wdApp = CreateObject("Word.Application")
wdApp.Documents.Open Filename:="R:SALESQuote Generators
Quotes2 Pass Tray2 Pass Tray Quote.doc" 'Opens File
SendKeys "{Left} {Enter}, False" 'Updates File
End If
End Sub

Can anyone help me to be able to open it as a non-read-only file...?

Hi there folks,

I know it's possible to open another document in Excel using VBA coding however is it possible to open a new Excel program (as you would if you went to Start>All Programs>Microsoft Office>Excel) and then open your new document in that?

The reason I ask is that I have two programs, both of which work fine in their own Excel program (even when open together on the same PC) however they become tempramental when open in the same copy of Excel. And I need one to open the other!

Thanks in advance,

Andy

Hi all I'm trying to open a word document from excel using VBA. Here is my code.

Sub Help_Click()

        Dim wdApp As Word.Application, wdDoc As Word.Document
        
        On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
        If Err.Number <> 0 Then 'Word isn't already running
        Set wdApp = CreateObject("Word.Application")
        End If
        On Error GoTo 0
        
        Set wdDoc = wdApp.Documents.Open(ThisWorkbook.Path & "Help.doc")
    
        wdApp.Visible = True
        
        wdDoc.Activate

End Sub
When I run the code I get the following error "User-defined type not defined". The line of code is highlighted in yellow. Any help will be greatly apprecaited.

Hi,

I wish to open text files i excel usign VBA with a delimiter as ~....I dont know how do we refer to the Other delimiter option...Following is my code

Private Sub CommandButton1_Click()
Dim varFileName
varFileName = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If TypeName(varFileName) = "String" Then
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & varFileName _
, Destination:=Range("A1"))
.Name = "AddEmployee"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = False
.TextFileOtherDelimiter = True
.Refresh BackgroundQuery:=False
End With
End If
End Sub
Can neone please help

Rgds
Vishal

Using Excel VBA, I am trying to copy data from one Excel
file to one Word file, and cycle back and forth between
the two files without opening a new Word file each time I
dump data from Excel into Word. When I use CreateObject,
I get a new instance of the Word file, but I don't know
how to use GetObject to activate an already open Word file
since the Word file is not saved yet and at this point is
just Document1. I don't want 20 instances of Word, just
one, with one Word file to contain all the dumped data.
Any ideas?

Hi everybody,

I have some troubles to open a word file from ACCESS in VBA.

The syntaxI use works only when Word is already opened.

Can U give me a code who works even if Word is closed

I mean a code that open word and open the file without troubles

Thank U

Hi Everyone,

i;m not familiar using the vb application in excel, can someone here know how to do the importing file to excel using vba.

1. i have attached the "dummy file" with form on it. i don't know how to show it up when the workbook is open. and you will see the import button. once the user hit the Import button it will show another form that will prompt the user to locate the file. the file would be "import template" which i have also attached.

i don't know how to code this.

i don't know how to transfer the data from import template to the dummy file vba.

thanks,
Albert

Hello,

I have an excel application which gets input data by importing xls files.

My problem:

I get the xls files from a different system so I can not change the way the are created.

When I try to open the input files in excel 2007 I get the error: "Excel found an unreadable content ...choose yes to repair ..."
If I choose "yes" and let excel solve the problem, it opens the file. After opening the file, If I press "save" and open it again with excel 2007 there is no problem.

If I open the original data file in excel 2003 there is no problem.

I have a VBA macro which import the data file to my application.
How can I handle the error using VBA and open the file despite this error ?

Thank you for your help

Hi,

Can anyone please provide me a code to copyall the pages of pdf file to excel using VBA.

I tried some of the code,But it works for only one page.

I want to copy all the pages in the PDF in a single stretch and copy the same to Excel.

Can anyone please provide the code for the same in VBA.

Thanks in Advance.
Karthik.

Hi

I regularly want to open .CSV files in excel but the problem is that if I was to just open it it will convert certain entries such as 1-7 to 01-Jan.

I know I can use the import data wizard and set the columns to text, but as I need to open maybe ten files several times a day this is very time consuming and open to error.

Is there a way in VBA of writing a routine to do it

When i am trying to open the word document through excel using http://
- url:

I am getting error:

unable to open use repiar option then try again.

and when i am trying to open manually it is prompting me with "Open",
"Save", "Cancel" dialoag box.

How do i eliminate this through code.

Please help

Hi,
I wondered whether it was possible to open office documents from within MS
Excel using hyperlinks to the related files. The documents in question are MS
Word format.

Cheers

Hi- hope someone can help with this pretty specific problem- I have just
upgraded to a new version of excel (2003), and have an issue with when I am
opening text files in excel.
If I open the txt value manually, I have no problem, all cells with dates in
them are recognised as dates.
When I open this file and bring it in using VBA, it recognises some of the
dates as text, and so screws my calculations.
I'm pretty sure that this is because it tries to bring them in in american
format, but has a problem when what it sees as the month goes above 12 (i.e
it brings it in as mm/dd/yyyy whereas the file is dd/mm/yyyy but this only
causes a problem if dd>12).
Of course I can correct this using date value or whatever, but I don;t want
to have to- is there a simple solution?

any help would be massively appreciated.
thanks in advance


I have written a small app the writes flat text files from excel
(order/routing tickets) and sends them to various different
printers around this place..

it is pretty simple and uses the

Open strfilename For Output Access Write Lock Write As #1
Print #1, " This is where the text goes" & string & ""

formats... I've just been asked to Bold some of the fields...I
don't think that is possible but I can't find any real info...
can someone tell me for sure yes or no?

Please?

Hi- hope someone can help with this pretty specific problem- I have just
upgraded to a new version of excel (2003), and have an issue with when I am
opening text files in excel.
If I open the txt value manually, I have no problem, all cells with dates in
them are recognised as dates.
When I open this file and bring it in using VBA, it recognises some of the
dates as text, and so screws my calculations.
I'm pretty sure that this is because it tries to bring them in in american
format, but has a problem when what it sees as the month goes above 12 (i.e
it brings it in as mm/dd/yyyy whereas the file is dd/mm/yyyy but this only
causes a problem if dd>12).
Of course I can correct this using date value or whatever, but I don;t want
to have to- is there a simple solution?

any help would be massively appreciated.
thanks in advance

When i am trying to open the word document through excel using http://
- url:

I am getting error:

unable to open use repiar option then try again.

and when i am trying to open manually it is prompting me with "Open",
"Save", "Cancel" dialoag box.

How do i eliminate this through code.

Please help

Hi list,

Use has some text files, and they want to use a macro to handle the process
that save these files to .csv format.

in each .txt file, each line contains data like:

"Code", "Date", "Position", etc.

If I open the .txt file and save it as .csv. if user open .csv file with
NotePad, it looks exactly like the .txt file before it saved to .csv. But if
open .txt file from Excel and save it to .csv, when user open it with
NotePad, all the "" gone, the line looks like:

Code, Date, Position, etc.

Does anyone know why this happened? If i want to use VBA to automit this
process for user, how can do it?

thanks for any suggestion.

Hi,
I wondered whether it was possible to open office documents from within MS
Excel using hyperlinks to the related files. The documents in question are MS
Word format.

Cheers

Hello,

After installing excel 2010, i´m not able to open xlsm files or access the VBA coding screen (View code for any excel sheet).

When i open .xlsm files it says:

Excel found unreadable content in 'Schema_2012.xlsm'. Do you want to recover the content of this workbook? If you trust the source of this workbook, click yes.

When i click yes, i get this:

Excel was able to open the file by repairing or removing the unreadable content.

Then i can see the link 'Click to view log file listing repairs':

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>error213200_01.xml</logFileName><summary>Errors were detected in file 'N:Tech SupportSchemaSchema_2012.xlsm'</summary>-<removedParts summary="Following is a list of removed parts:"><removedPart>Removed Part: /xl/vbaProject.bin part. (Visual Basic for Applications (VBA))</removedPart></removedParts></recoveryLog>

If i open new blank excel sheet i noticed that i´m not able to access ''VBA screen / View code screen'.
I did enable both ActiveX and Macros in File -> Options -> Trust center. The change did nothing.

Q1) Does anyone know how the get VBA working in Excel 2010?
Q2) How i can open xlsm files? The answer would probably be to get VBA working first.

The project I am working on imports event report files from power system relays and plots their voltage and current waveforms. I am trying to import 2 different types of files into Excel via VBA by utilizing a UserForm. The first type of file is a comma separated file, and I have successfully imported it. The next file is a bit tricky for me. I want it in the same format in Excel as the csv file. Please see the attached files for what I'm talking about. I want to import files in the form of "221Btext" into Excel in the same format as "sample sheet." One of the differences in the formats once "221Btxt" is in Excel is that I need to figure out how to separate the items under "Relays," "Outputs," and "Inputs" into their own column. These items read downward, i.e., under "Relays" you would read the items as "50P," "213," "21P," etc.

Also, to throw another kink in the mix: in "sample sheet," the values in B6 (samples per cycle) and D6 (number of cycles) are important, but they are not included in "221Btxt." To figure out the samples per cycle in "221Btxt" you count the lines of data before a blank row (in this case, 4), and the number of cycles is the number of groups of 4 (in this case, 11). I also need code to go through the file, figure this info out, and insert each piece of info into its own cell. This will insert info into two additional cells that I can then use for plotting the waveforms.

Can anyone help me??????? I'm new to VBA and having a hard time with this. Thanks!

Hi there,
I need to create a Word document from Excel in which I would like to insert
the date/time and file name (insert Auto Text) in the header through VBA. In
fact, I can create the Word file from Excel but encounter error when it comes
to inserting date and file name in the header.
Appreciate if anyone is kind enough to help me out.

Thanks in advance for your kind assistance!
Regards,

Steve C.

Hello all

Is it possible to detect which application call the MS Excel using VBA?

I want to put some conditions in the Workbook_Open() method.

IF MS Word call Then
Do Job 1
Else
Do Job 2

Any methods for doing it?

Thanks
Bon

hey

I would like to control wordpad from Excel using VBA. I.e. open a wordpad document write something into it and save it again afterwards.

cheers

I have several text files in a folder which I wish to open one at a time in order to copy the data into a spreadsheet.
e.g. I want to open text file #1, copy the data, then close the file, open text file #2 copy the data and close the file, and so on for all of the files in the directory.

Any help I could get on the code required to open the files in this way would be greatly appreciated!!


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