Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

As the macro that creates a text file with value?

Posted on 2011-03-18
5
Medium Priority
?
206 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:Thomas_Meyer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 35166178
There are several challenges here - accessing the control, appending to a log file, and finding the temporary filde path
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 35166185
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

Open in new window

0
 

Author Comment

by:Thomas_Meyer
ID: 35167574
I do not know what's wrong, but I do not create the file %TEMP%\test.log.
Otherwise the %TEMP% I like: Environ("TEMP")
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 35167823
OK, change the function to:

Public Function strTempFolder() As String
    strTempFolder = Environ("TEMP")
End Function

They both work in my tests.
0
 

Author Closing Comment

by:Thomas_Meyer
ID: 35168503
Perfect work! Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question