H
HankNJ
Hello: I have cut/pasted an Excel chart onto a PowerPoint slide. Now I
am using "Open" and "Line Input" to import lines of text from a CSV
(comma separated value) file into the embedded worksheet. This all
works OK.
The final step would be to parse the inported lines using
TextToColumns, but I can't get it to work. This is what I have so
far...
Sub UpdateCharts()
'
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet
Dim shpGraph As PowerPoint.Shape
Dim fileArray(0 To 15) As String
fileArray(0) = "C:\CPSCharts\CBTSS1.CSV"
fileArray(1) = "C:\CPSCharts\CBTSS2.CSV"
fileArray(2) = "C:\CPSCharts\CBTSS3.CSV"
fileNum = 0
ActiveWindow.Panes(2).Activate
' Loop through each slide in the ActivePresentation
For a = 1 To ActivePresentation.Slides.Count
ActiveWindow.View.GotoSlide Index:=a
Set shpGraph = ActivePresentation.Slides(a).Shapes("CPSChartObject")
Set oWB = shpGraph.OLEFormat.Object
Set oWS = oWB.Worksheets(1)
Open fileArray(fileNum) For Input As #1
fileNum = fileNum + 1
lineCnt = 0
wordCnt = 0
' Load each line into array, load each array member into a
datasheet cell
Do While Not EOF(1)
Line Input #1, lValue
wordArray = Split(lValue, ",")
wordCnt = UBound(wordArray) - LBound(wordArray) + 1
' Load each comma delimited line into a cell in column B...
oWS.Range("B2").Offset(lineCnt, 0).Value = lValue
' **********************************************
' This part fails with Runtime error 1004...
' Select Method Of Range Class Failed
' **********************************************
oWS.Range("B2").Offset(lineCnt, 0).Select
Selection.TextToColumns Destination:=Range("B2"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False
lineCnt = lineCnt + 1
Loop
Close #1
Set oWB = Nothing ' Release object
Set oWS = Nothing
Next a
ActiveWindow.View.GotoSlide Index:=1
Application.ActiveWindow.ViewType = myView
MsgBox ("UpdateCharts has ended")
End Sub
Please help. I can't seem to select the column. If there's a better
way to do this I would also be interested in hearing that...
Thanks ... HANK : )
am using "Open" and "Line Input" to import lines of text from a CSV
(comma separated value) file into the embedded worksheet. This all
works OK.
The final step would be to parse the inported lines using
TextToColumns, but I can't get it to work. This is what I have so
far...
Sub UpdateCharts()
'
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet
Dim shpGraph As PowerPoint.Shape
Dim fileArray(0 To 15) As String
fileArray(0) = "C:\CPSCharts\CBTSS1.CSV"
fileArray(1) = "C:\CPSCharts\CBTSS2.CSV"
fileArray(2) = "C:\CPSCharts\CBTSS3.CSV"
fileNum = 0
ActiveWindow.Panes(2).Activate
' Loop through each slide in the ActivePresentation
For a = 1 To ActivePresentation.Slides.Count
ActiveWindow.View.GotoSlide Index:=a
Set shpGraph = ActivePresentation.Slides(a).Shapes("CPSChartObject")
Set oWB = shpGraph.OLEFormat.Object
Set oWS = oWB.Worksheets(1)
Open fileArray(fileNum) For Input As #1
fileNum = fileNum + 1
lineCnt = 0
wordCnt = 0
' Load each line into array, load each array member into a
datasheet cell
Do While Not EOF(1)
Line Input #1, lValue
wordArray = Split(lValue, ",")
wordCnt = UBound(wordArray) - LBound(wordArray) + 1
' Load each comma delimited line into a cell in column B...
oWS.Range("B2").Offset(lineCnt, 0).Value = lValue
' **********************************************
' This part fails with Runtime error 1004...
' Select Method Of Range Class Failed
' **********************************************
oWS.Range("B2").Offset(lineCnt, 0).Select
Selection.TextToColumns Destination:=Range("B2"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False
lineCnt = lineCnt + 1
Loop
Close #1
Set oWB = Nothing ' Release object
Set oWS = Nothing
Next a
ActiveWindow.View.GotoSlide Index:=1
Application.ActiveWindow.ViewType = myView
MsgBox ("UpdateCharts has ended")
End Sub
Please help. I can't seem to select the column. If there's a better
way to do this I would also be interested in hearing that...
Thanks ... HANK : )