473,379 Members | 1,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

VBA to Word problem

Can anyone help with the following frustration?

I am trying to export a report into a Word Document with a specific
template. The code snippets are:

Dim Wrd As Word.Application
Dim objDocs As Object
Dim strLetter As String
Dim strTemplateDir As String
Dim prps As Object
Dim blnWordRunning As Boolean

........... Wrd.ChangeFileOpenDirectory _
"C:\Documents and Settings\STEPHEN LAYTON\Desktop\PDF\"
Wrd.Selection.InsertFile Filename:="ContractorCopy_379-05.rtf",
Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
and all works fine. However, change the file name to a variable passed
from another module and I get the error message that the file cannot be
found (despite debug.print the variable and checking the name. The
revised code is:

Wrd.ChangeFileOpenDirectory _
"C:\Documents and Settings\STEPHEN LAYTON\Desktop\PDF\"
Wrd.Selection.InsertFile Filename:=strFile, Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False

Any ideas?

--
Public Key: http://www.pgp.uk.demon.net/pks/pks-commands.html -
0x36EA37F5

Nov 13 '05 #1
2 3164
I'm not sure, but just an idea.

If you already know the directory is going to be "C:\Documents and
Settings\STEPHEN LAYTON\Desktop\PDF\", why don't you try giving the filename
together with the path, i.e., "C:\Documents and Settings\STEPHEN
LAYTON\Desktop\PDF\" & strFile.

Hope it works.

Herbert

<wi********************@yahoo.co.uk> ¦b¶l¥ó
news:Te**************@layton.demon.co.uk ¤¤¼¶¼g...
Can anyone help with the following frustration?

I am trying to export a report into a Word Document with a specific
template. The code snippets are:

Dim Wrd As Word.Application
Dim objDocs As Object
Dim strLetter As String
Dim strTemplateDir As String
Dim prps As Object
Dim blnWordRunning As Boolean

.......... Wrd.ChangeFileOpenDirectory _
"C:\Documents and Settings\STEPHEN LAYTON\Desktop\PDF\"
Wrd.Selection.InsertFile Filename:="ContractorCopy_379-05.rtf",
Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
and all works fine. However, change the file name to a variable passed
from another module and I get the error message that the file cannot be
found (despite debug.print the variable and checking the name. The
revised code is:

Wrd.ChangeFileOpenDirectory _
"C:\Documents and Settings\STEPHEN LAYTON\Desktop\PDF\"
Wrd.Selection.InsertFile Filename:=strFile, Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False

Any ideas?

--
Public Key: http://www.pgp.uk.demon.net/pks/pks-commands.html -
0x36EA37F5

Nov 13 '05 #2
Herbert

Many thanks for your reply. It works beautifully.

Stephen

In article <43**********@rain.i-cable.com>, Herbert Chan
<he*****@chan.com> writes
I'm not sure, but just an idea.

If you already know the directory is going to be "C:\Documents and
Settings\STEPHEN LAYTON\Desktop\PDF\", why don't you try giving the filename
together with the path, i.e., "C:\Documents and Settings\STEPHEN
LAYTON\Desktop\PDF\" & strFile.

Hope it works.

Herbert

<wi********************@yahoo.co.uk> ¦b¶l¥ó
news:Te**************@layton.demon.co.uk ¤¤¼¶¼g...
Can anyone help with the following frustration?

I am trying to export a report into a Word Document with a specific
template. The code snippets are:

Dim Wrd As Word.Application
Dim objDocs As Object
Dim strLetter As String
Dim strTemplateDir As String
Dim prps As Object
Dim blnWordRunning As Boolean

.......... Wrd.ChangeFileOpenDirectory _
"C:\Documents and Settings\STEPHEN LAYTON\Desktop\PDF\"
Wrd.Selection.InsertFile Filename:="ContractorCopy_379-05.rtf",
Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
and all works fine. However, change the file name to a variable passed
from another module and I get the error message that the file cannot be
found (despite debug.print the variable and checking the name. The
revised code is:

Wrd.ChangeFileOpenDirectory _
"C:\Documents and Settings\STEPHEN LAYTON\Desktop\PDF\"
Wrd.Selection.InsertFile Filename:=strFile, Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False

Any ideas?

--
Public Key: http://www.pgp.uk.demon.net/pks/pks-commands.html -
0x36EA37F5




Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Joan | last post by:
I am creating a word document from an asp page. I have no problems actaully creating the document and creating some tables that have data in them. I am using Response.ContentType =...
8
by: Jaime Rios | last post by:
Hi, I created a COM AddIn for Word that performs the functions that it needs to, but I needed to add the ability for the toolbar created by the COM AddIn to remember it's last position and...
5
by: Stefania Scott | last post by:
I am trying to print a word document from Access. The code I've written works well in my computer but does not in the one were it is needed. Here the piece of code: 'doc path strObjectPath =...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
5
by: Jerry Hull | last post by:
I'm working with a database developed by an untrained person over several years - and on a network that has recently been upgraded with a new server installed and MS office upgraded from 2K (I...
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
5
by: Niklas Uhlin | last post by:
Someone please explain why Session_Start fires multiple times / retains SessionID values between sessions, when you open an ASP.NET page from MS Word. For details of the problem, see below: 1....
16
by: Simon Verona | last post by:
I have a problem with automating MS Word through vb.net My code is : Dim objword As new Word.ApplicationClass Try objWord.Documents.Open(letterfile)...
10
by: longshan | last post by:
Hi friends, Can you help me write some code to list all the arrangement of a word? for example "unix" it has possibilities like nixu,ixun,,,and so on. I think we can get 4!(4*3*2*!)=24...
209
by: arnuld | last post by:
I searched the c.l.c archives provided by Google as Google Groups with "word input" as the key words and did not come up with anything good. C++ has std::string for taking a word as input from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.