Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming,microsoft.public.office.developer.vba,microsoft.public.word.tables,microsoft.public.word.vba.general
hornbecky83 hornbecky83 is offline
external usenet poster
 
Posts: 5
Default Show actual name of file path after you have renamed it

Hi everyone-

I am writing a code in excel VBA for word. I am linking tables from
various excel files to one word document. I need to specifiy which
excel file table is placed into the word document. The code opens up
several excel files of the users choosing, renames that path to
something more general (Study Opt1FE1), and then this is where the
difficulty comes in. I am running for loops and when a certain
combination of numbers in the for loops matches what I renamed my path
files to, the code will link that files tables to my word document.
The code for linking the tables is as follows without the renamed file
path:

Wdoc.Fields.Add Range:=rng, _
Text:="LINK Excel.Sheet.8 ""C:\\Documents and
Settings\\shornbec\\Desktop\\sarah\\excel
templates\\Mission.FY07Q1_Sarah.xls"" ""Report Tables!CostSummaryK"" \a
\f 4 \h", PreserveFormatting:=True

I renamed the C:\\ path to something like "Study Opt1FE2". But the
link will not work when C:\\...is replaced with Study Opt1FE2. Is
there a way that I can have the renamed value display the file path
name value, so I can put the old name value into my text link?

This is the code that I was trying to get the study Opt1FE1 to work.

Dim Wdoc As Word.document
Dim Wapp As Word.Application
Dim rng As Word.Range
Dim x As Integer
Dim y As Integer
Dim vrtSelectedItem As Variant
Dim lngCount As Long
Dim tablestring As String

Sub create_document()

Set Wapp = CreateObject("Word.Application")
Wapp.Visible = True
Wapp.Documents.Add
Set Wdoc = Wapp.ActiveDocument

Call UseFileDialogOpen()

End sub

Public Sub UseFileDialogOpen()

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Show

For lngCount = 1 To .SelectedItems.Count
MsgBox .SelectedItems(lngCount)
Next lngCount

'renames file path to more generic names with slight number variations
For Each vrtSelectedItem In .SelectedItems
Workbooks.Open vrtSelectedItem
a = Worksheets("Report Tables Delta V").Range("B1") ' Options
b = Worksheets("Report Tables Delta V").Range("D1") 'Flight
Elements
vrtSelectedItem = "Study Opt" & a & "FE" & b
MsgBox vrtSelectedItem
Next
End With

ThisWorkbook.Activate
Worksheets("more options").Activate
x = Worksheets("more options").Range("A1")
y = Worksheets("more options").Range("A2")

For i = 1 to x
For j = 1 to y

'i was putting together a string that could go in the text link below,
but the Study Opt1FE1 remains. Is
'there a way to get it to display its pathname? I just want the
studyopt1fe1 there so the code now
'where to get the specific excel file's table from.

tablestring = "LINK Excel.Sheet.8" & Chr(34) & Chr(34) & "Study Opt" &
i & "FE" & j & Chr(34) & Chr(34) & """ Report Tables Delta
V!MissionTimelineDeltaVBudgetTable"" \a \f 4 \h"

Wdoc.Fields.Add Range:=rng, _
Text:=tablestring, PreserveFormatting:=True

 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't open file in Office 2003 Word or Excel from Windows Explorer Larry Frohman Microsoft Word Help 11 November 16th 06 02:55 PM
How do I correct a corrupt MS WORD file (name or path invalid)? do_ron Microsoft Word Help 2 November 15th 05 02:50 PM
What is the maximum number of characters you can use to name a fil nilufer Microsoft Word Help 3 June 15th 05 11:14 AM
How do you set last file opened to show in file list 1st Miazelli Microsoft Word Help 5 December 20th 04 09:19 PM
Macro that will add the file path & date to Word footnotes? Rich P Microsoft Word Help 2 December 15th 04 07:49 PM


All times are GMT +1. The time now is 12:29 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"