Thomas_Meyer
asked on
As the macro that creates a text file with value?
Hi,
can you help me with a macro that creates a text file and writes the value?
Macro to find and write the value control label1 (located on the first slide) into a text file %TEMP%\test.log
If the folder %TEMP% this .log file is located, must be automatically replaced.
Example in the attached presentation.
Thanks in advance for your help. TEST.ppt
can you help me with a macro that creates a text file and writes the value?
Macro to find and write the value control label1 (located on the first slide) into a text file %TEMP%\test.log
If the folder %TEMP% this .log file is located, must be automatically replaced.
Example in the attached presentation.
Thanks in advance for your help. TEST.ppt
There are several challenges here - accessing the control, appending to a log file, and finding the temporary filde path
This is the code:
Option Explicit
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Sub WriteToFile()
Dim sl As Slide
Dim sh As Shape
Dim ctl As Control
Set sl = ActivePresentation.Slides(1)
Set sh = sl.Shapes(1)
For Each sh In sl.Shapes
If sh.Type = msoOLEControlObject Then
If sh.OLEFormat.Object.Name = "Label1" Then
WriteLog sh.OLEFormat.Object.Caption
End If
End If
Next sh
End Sub
Sub WriteLog(ByVal Text As String)
Dim f As Integer
Dim strFileName As String
strFileName = "\test.log"
'Text = Format$(Now, "HH:nn:ss") & " " & Text
Debug.Print Text
f = FreeFile
Open strTempFolder & strFileName For Append As #f
Print #f, Text
Close #f
End Sub
Public Function strTempFolder() As String
Dim strDir As String
Dim r As Long
strDir = Space$(512)
r = GetTempPath(Len(strDir), strDir)
If r > 0 Then
strTempFolder = Left(strDir, r - 1)
Else
strTempFolder = ""
End If
End Function
ASKER
I do not know what's wrong, but I do not create the file %TEMP%\test.log.
Otherwise the %TEMP% I like: Environ("TEMP")
Otherwise the %TEMP% I like: Environ("TEMP")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect work! Thanks