none
Problems using information from two different csv files in Power Point RRS feed

  • Question

  • Hi,

    I'm attempting to import two different csv files for slides in Power Point.

    My code looks like this:

        Dim Input_file As Variant
        Dim PedUsage_file As Variant
        Dim dlgOpen As FileDialog
        Dim FileNum As Integer
        Dim PedFileNum As Integer
        Dim PedBuffer As Variant
        Dim logBuffer As Variant
        Dim pedInfo As Variant
        Dim logData As Variant
    
        Set dlgOpenPed = Application.FileDialog(Type:=msoFileDialogOpen)
        dlgOpenPed.AllowMultiSelect = False
        If dlgOpenPed.Show = -1 Then
            PedUsage_file = dlgOpenPed.SelectedItems.Item(1)
        End If
    
        Set dlgOpenLog = Application.FileDialog(Type:=msoFileDialogOpen)
        dlgOpenLog.AllowMultiSelect = False
        If dlgOpenLog.Show = -1 Then
            Input_file = dlgOpenLog.SelectedItems.Item(1)
        End If
    
        MaxImage = 4
        
        FileNum = FreeFile(1)
        PedFileNum = FreeFile(2)
        Open PedUsage_file For Input As FreeFile(2)
        Open Input_file For Input As FreeFile(1)
        TotalSlides = 0
        While Not EOF(PedFileNum)
            Line Input #PedFileNum, PedBuffer
            pedInfo = Split(PedBuffer, ",")  'split text at ","
            MsgBox (pedInfo(0))
            MsgBox (pedInfo(1))
    ...
                        For i = 0 To MaxImage
                            Line Input #FileNum, logBuffer
                            logData = Split(logBuffer, ",")  'split text at ","
                            MsgBox (logData(0))
                            MsgBox (logData(1))
                            MsgBox (logData(2))
                            MsgBox (logData(3))
                            MsgBox (logData(4))
                            MsgBox (logData(5))
                            MsgBox (logData(6))
                            MsgBox (logData(7))
                            MsgBox (logData(8))
    

    This is clearly not working. When I get to the point of using the "logData" array I can tell that it is still using information from the "PedUsage_file". Because the "PedUsage_file" only has two columns per row - I get a "Subscript out of range" error on logData(2).

    The csv file for "Input_File" has 9 columns per row.

    Thanks in advance for any help.

    Wednesday, May 23, 2012 11:34 PM

Answers

  • Sorry, my bad. Use

        PedFileNum = FreeFile
        Open PedUsage_file For Input As PedFileNum
        FileNum = FreeFile
        Open Input_file For Input As FileNum


    Regards, Hans Vogelaar

    • Marked as answer by Kip Guerrero Thursday, May 24, 2012 2:29 PM
    Thursday, May 24, 2012 5:50 AM

All replies

  • Change

        FileNum = FreeFile(1)
        PedFileNum = FreeFile(2)
        Open PedUsage_file For Input As FreeFile(2)
        Open Input_file For Input As FreeFile(1)

    to

        FileNum = FreeFile
        PedFileNum = FreeFile
        Open PedUsage_file For Input As PedFileNum
        Open Input_file For Input As FileNum


    Regards, Hans Vogelaar

    Thursday, May 24, 2012 5:22 AM
  • Thanks for responding again Hans,

    When I implement this code I get a run time error: "file already open" at the line for:

    Open Input_file For Input As FileNum

    Thursday, May 24, 2012 5:40 AM
  • Sorry, my bad. Use

        PedFileNum = FreeFile
        Open PedUsage_file For Input As PedFileNum
        FileNum = FreeFile
        Open Input_file For Input As FileNum


    Regards, Hans Vogelaar

    • Marked as answer by Kip Guerrero Thursday, May 24, 2012 2:29 PM
    Thursday, May 24, 2012 5:50 AM
  • That's the ticket Hans! And it makes sense too. THANK YOU!
    Thursday, May 24, 2012 2:30 PM