PDA

View Full Version : Auto run macro and inserting text



alaou
04-19-2011, 06:39 AM
Hello all

I'm new , so i need your help.

My first goal i want to achieve is how macro run automatically with presentation opening.

Second, i want to insert text in slide 6,in ONE textbox from many *.txt files.

Thanks in advance.

Cosmo
04-19-2011, 08:52 AM
Hello all

I'm new , so i need your help.

My first goal i want to achieve is how macro run automatically with presentation opening.

Second, i want to insert text in slide 6,in ONE textbox from many *.txt files.

Thanks in advance.
Powerpoint does not have a provision for auto running a macro (aside from creating an Add-In). I believe there is a way to possibly do so with 2007, although it requires editing the presentation's xml code (IIRC). Not sure if 2010 adds any new feature to do this, but I don't believe it does.

alaou
04-22-2011, 06:34 AM
Sub Μακροεντολή4()
Dim FileName As String
Dim FileNum As Integer
Dim InputBuffer As String
ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHoriz ontal, 93.5, 88.625, 544.375, 28.875).Select
ActiveWindow.Selection.ShapeRange.TextFrame.WordWrap = msoTrue
With ActiveWindow.Selection.TextRange.ParagraphFormat
.LineRuleWithin = msoTrue
.SpaceWithin = 1
.LineRuleBefore = msoTrue
.SpaceBefore = 0.5
.LineRuleAfter = msoTrue
.SpaceAfter = 0
End With
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
With ActiveWindow.Selection.TextRange
FileName = "C:\text1.txt"
FileNum = FreeFile
If Dir$(FileName) <> "" Then
Open FileName For Input As FileNum
While Not EOF(FileNum)
Input #FileNum, InputBuffer
.Text = InputBuffer
Wend
Close FileNum
End If
With .Font
.Name = "Arial"
.Size = 18
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.SchemeColor = ppForeground
End With
End With
End Sub

John Wilson
04-22-2011, 08:36 AM
My guess is that would add only the last line of the text file?

Try this maybe

Sub trythis()
Dim strtext As String
Dim osld As Slide
Dim oshp As Shape
Dim FileName As String
Dim FileNum As Integer
Dim InputBuffer As String
Set osld = ActiveWindow.View.Slide
'set osld=ActivePresentation.Slides(6) maybe?
Set oshp = osld.Shapes.AddTextbox(msoTextOrientationHorizontal, 93.5, 88.625, 544.375, 28.875)
oshp.TextFrame.WordWrap = msoTrue
With oshp.TextFrame.TextRange.ParagraphFormat
.LineRuleWithin = msoTrue
.SpaceWithin = 1
.LineRuleBefore = msoTrue
.SpaceBefore = 0.5
.LineRuleAfter = msoTrue
.SpaceAfter = 0
End With
FileName = "C:\text1.txt"
FileNum = FreeFile
If Dir$(FileName) <> "" Then
Open FileName For Input As FileNum
While Not EOF(FileNum)
Input #FileNum, InputBuffer
strtext = strtext & InputBuffer & vbCrLf
Wend
Close FileNum
End If
With oshp.TextFrame.TextRange
.Text = strtext
With .Font
.Name = "Arial"
.Size = 18
.Color.SchemeColor = ppForeground
End With
End With
End Sub

In any case this is the easy bit. Making it run automatically is going to be much harder and also it doesn't add to slide 6 nor from many text boxes

alaou
04-22-2011, 09:31 AM
Ok. thanks a lot,i'll try it...

p.s. Yes, i insert only one line from the text, the last one.

John Wilson
04-22-2011, 10:15 AM
It's not clear if you WANT to just insert the last line. My code should insert it all. I meant many text FILES of course.

alaou
04-22-2011, 12:29 PM
It's not clear if you WANT to just insert the last line. My code should insert it all. I meant many text FILES of course.

Yes, i saw it. Thanks a lot!

I find a way to insert text from many files but it's not the right way.

It seems that the correct way is to create a *.txt file with the contents of all other txt files and then insert all of the content from the new txt file.

I working on it... because i'm new one, i try to find a way to read and write in txt files.....

John Wilson
04-26-2011, 07:21 AM
It's perfectly possible to loop through all the text files in one folder. Would that work?

alaou
04-27-2011, 11:27 PM
Yes! It worked....!!:bow:

Thanks a lot. Your help was most valuable.

But now i faced another problem... and i have to check it.

The *.ppt created fine and works. But in some pc's the picture that i have added doesn't show up. Really strange.