Importing a changing text file

  • Thread starter Thread starter Simon Keeling
  • Start date Start date
S

Simon Keeling

Hi,

I have a text file which changes 6-times daily (it contains weather
data).

Is it possible to imort this text file and for it to automatically
update when I load the powerpoint presntation, pretty much link
linking to an image?

Thanks in advance,
Simon Keeling
 
I guess reading from txt file doesnt have any problem and will be getting
updated data too. Also you can use auto events to load the macro at the load
of powerpoint.

Sub ReadTextToTextFrame()
'load data to textframe of a shape
ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text =
GetText("C:\\test.txt")
End Sub
'http://www.exceluser.com/explore/questions/vba_textcols.htm
Function GetText(sFile As String) As String
Dim nSourceFile As Integer, sText As String

''Close any open text files
Close

''Get the number of the next free text file
nSourceFile = FreeFile

''Write the entire file to sText
Open sFile For Input As #nSourceFile
sText = Input$(LOF(1), 1)
Close

GetText = sText
End Function

This function will load the data from txt file to the textframe. You can
call this fuction at the start up.
http://skp.mvps.org/autoevents.htm

Another option is to create an addin which populates data from the file
 
A couple of minor quibbles:
Sub ReadTextToTextFrame()
'load data to textframe of a shape
ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text =
GetText("C:\\test.txt")

Make that:
GetText("C:\test.txt")

One backslash instead of two
End Sub
'http://www.exceluser.com/explore/questions/vba_textcols.htm
Function GetText(sFile As String) As String
Dim nSourceFile As Integer, sText As String

''Close any open text files
Close

''Get the number of the next free text file
nSourceFile = FreeFile

''Write the entire file to sText
Open sFile For Input As #nSourceFile
sText = Input$(LOF(1), 1)

Just be aware that this will bite you if the text file is double-byte encoded
(ie, in Chinese/Japanese/Korean etc) or, I suspect, Unicode.

A routine that reads a line of input at a time and appends it to sText solves
that problem. In theory it's a bit slower. In practice, unless your files are
huge, there'll be no difference.
 
Thanks Steve

Steve Rindsberg said:
A couple of minor quibbles:


Make that:
GetText("C:\test.txt")

One backslash instead of two


Just be aware that this will bite you if the text file is double-byte encoded
(ie, in Chinese/Japanese/Korean etc) or, I suspect, Unicode.

A routine that reads a line of input at a time and appends it to sText solves
that problem. In theory it's a bit slower. In practice, unless your files are
huge, there'll be no difference.


-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
Back
Top