Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Open a WorkBook - from Word
Message
From
09/07/2001 10:01:38
 
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00527189
Message ID:
00528085
Views:
25
Hello Eric,

Thanks for hanging with me. Yes I got the "Set" statement. Another significant difference VBA and VFP/VBA in how to create an object.

In the code below I get as far as ".Range("A1") = "Open Text Method""
That along with the rest of the code I recorded in Excel. But won't work when part of this Word macro.

I'm begining to wonder if there is a better way. The reason for moving the data into Excel (or Access) is to enable field reference when replacing a field, from a comma delimited text file, into the Word label template. Example: Find/Replace <> WITH Row 1 Column A (I know that's not the precise syntax).

I've written about a dozen VFP/VBA programs that send letters using a VFP file to a Word document. So I thought this would be a good way to break into VBA/VB
programmng. NOT! But I hate to give up when I may be close. Thanks for your help. Have a nice day.

Regards,

Paige

Private Sub UserForm_Initialize()
'
Dim strFileArray() As String
Dim strFFile As String
Dim intCount As Integer

'
strFFile = Dir("C:\My Documents\*.txt")
intCount = 1
'
Do While strFFile <> ""
If strFFile <> "." And strFFile <> ".." Then
ReDim Preserve strFileArray(intCount)
strFileArray(intCount) = strFFile
intCount = intCount + 1
strFFile = Dir()
End If
'
Loop
'
lstFiles.List() = strFileArray
'
'End Sub
'

'**
Documents.Open ("c:\myDocu~1\MyLabels.doc")
If Documents.Count = 0 Then _
MsgBox "This procedure will not run without a " _
& "document open.", vbOKOnly + vbExclamation, _
"No Document Is Open"


Dim MySpreadSheet As Object
Set MySpreadSheet = GetObject("c:\myDocu~1\MyLabels.xls")
With MySpreadSheet
.Application.Visible = True
.Worksheets.Add
.Range("A1") = "Open Text Method"
.Range("A2").Select

.OpenText FileName:=strFFile '\import text to temporary worksheet
.ActiveSheet.UsedRange.Select '\ select imported text in temporary workbook
.Selection.Copy '\ copy to clipboard
.Close '\ close temporary workbook
.ActiveSheet.Paste '\ paste text into your workbook

' .QueryTables.Add(Connection:= _
' "TEXT;C:\My Documents\Labels.txt", Destination:=MySpreadSheet.Range("A1"))
' .Name = "Labels"
' .FieldNames = True
' .RowNumbers = False
' .FillAdjacentFormulas = False
' .PreserveFormatting = True
' .RefreshOnFileOpen = False
' .RefreshStyle = xlInsertDeleteCells
' .SavePassword = False
' .SaveData = True
' .AdjustColumnWidth = True
' .RefreshPeriod = 0
' .TextFilePromptOnRefresh = False
' .TextFilePlatform = xlWindows
' .TextFileStartRow = 1
' .TextFileParseType = xlDelimited
' .TextFileTextQualifier = xlTextQualifierDoubleQuote
' .TextFileConsecutiveDelimiter = False
' .TextFileTabDelimiter = True
' .TextFileSemicolonDelimiter = False
' .TextFileCommaDelimiter = True
' .TextFileSpaceDelimiter = False
' .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
' .Refresh BackgroundQuery:=False
End With
'End Sub
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform