Link to home
Create AccountLog in
Avatar of neelyjer
neelyjerFlag for United States of America

asked on

VBA Macro Error

Hello Experts,

     The macro below was recorded by excel and modified by myself.  The second macro is exactly what Excel recorded.  It is supposed to go to ABCD.xls , select all the cells on a sheet, copy them, go back to  the original WXYZ.xls, select all the cells, and paste the data from ABCD.xls.  However, when I execute my edited macro I get the following error:

Run-Time Error '1004':
Application-Defined or object-defined error

I stepped through the code and found that the is occuring on 'Cells.Select'.

            Windows("VD" & Trim(inputDat) & ".csv").Activate
            Sheets("VD" & Trim(inputDat) & "").Activate
            Cells.Select
            Selection.Copy
            Windows("VXW." & Trim(InputWDat) & ".xls").Activate
            Sheets("" & Trim(inputDay) & "").Select
            Cells.Select
            ActiveSheet.Paste



When I execute the recorded macro, it works just fine.
'************Recorded Macro*****************

    Windows("VD070603.csv").Activate
    Cells.Select
    Selection.Copy
    Windows("Vinnie.20070603.xls").Activate
    Sheets("SUN").Select
    Cells.Select
    ActiveSheet.Paste

What the hell's going on?
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Which line does it fail on, and what to the strings resolve to?

Also, does the name of the 'day' sheet actually have double quotes at the beginning and end?
Forget about the double quotes. They are just zero-length strings, as you must know.
Try this version of your code:

            Workbooks("VD" & Trim(inputDat) & ".csv").Sheets("VD" & Trim(inputDat)).Activate
            Cells.Select
            Selection.Copy
            Workbooks("VXW." & Trim(InputWDat) & ".xls").Sheets(Trim(inputDay)).Activate
            Cells.Select
            ActiveSheet.Paste

Kevin
Avatar of neelyjer

ASKER

Zorvek,

     I get the same response.
ASKER CERTIFIED SOLUTION
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Zorvek,

     I have moved everything into a form to allow myself to mask an input box.  Below is the code.  I added both of you suggestions and got the same response I've been getting with your first code, and got a different response on the second.  The second code gives me a suscript out of range error for  your code, " .UsedRange.Copy Workbooks("VXW." & ......"

Private Sub cmdDay_Click()

    txtDay.Visible = False
    lblDay.Visible = False
    lblDaya.Visible = False
    cmdDay.Visible = False
    txtSht.Visible = True
    lblSht.Visible = True
    lblShta.Visible = True
    cmdSht.Visible = True

    frmExtract.Caption = "Tandem ID"
End Sub
Private Sub cmdSht_Click()

    txtSht.Visible = False
    lblSht.Visible = False
    lblShta.Visible = False
    cmdSht.Visible = False
    txtID.Visible = True
    lblTID.Visible = True
    lblTIDa.Visible = True
    cmdTID.Visible = True

    frmExtract.Caption = "Tandem ID"
    frmExtract.Hide

'***************************************************************************************************
'Set Variable Types
'***************************************************************************************************
Dim PathInfo As String
  Dim objFSO, promptStr, inputDat, CSVFileDet, CSVFileSum, sheetName, NewNameD, NewNameS, i
  Set objDet = CreateObject("Scripting.FileSystemObject")
 
'***************************************************************************************************
' Get Tandem Logon ID & PW.
'***************************************************************************************************
 
'  promptStr = ""
'  defaultStr = ""
'  'Do While True
'     promptStr = promptStr & "Enter your Tandem ID."
'     promptStr = promptStr & vbNewLine & vbNewLine
'     inputID = InputBox(promptStr, "Import File", defaultStr)
     inputID = frmExtract.txtID.Value
         
'     promptStr = promptStr & "Enter your Tandem password."
'     promptStr = promptStr & vbNewLine
'     InputPW = InputBox(promptStr, "Import File", defaultStr)
     InputPW = frmExtract.txtPW
         
'***************************************************************************************************
' Get week beginning date.
'***************************************************************************************************
     
'     promptStr = promptStr & "Enter the week beginning date. (yyyymmdd)"
'     promptStr = promptStr & vbNewLine
'     InputWDat = InputBox(promptStr, "Import File", defaultStr)
     InputWDat = frmExtract.txtWeek
         

'***************************************************************************************************
' Get extract day for worksheet.
'***************************************************************************************************
     
'     promptStr = promptStr & "Enter the day of extract."
'     promptStr = promptStr & vbNewLine
'     promptStr = promptStr & "Use one of the following:"
'     promptStr = promptStr & vbNewLine
'     promptStr = promptStr & "Sun" & vbNewLine
'     promptStr = promptStr & "Mon" & vbNewLine
'     promptStr = promptStr & "Tues" & vbNewLine
'     promptStr = promptStr & "Wed" & vbNewLine
'     promptStr = promptStr & "Thu" & vbNewLine
'     promptStr = promptStr & "Fri" & vbNewLine
'     promptStr = promptStr & "Sat" & vbNewLine
'     inputDay = InputBox(promptStr, "Import File", defaultStr)
     inputDay = frmExtract.txtSht
     
 
'***************************************************************************************************
' Get date of file needed to be imported to Excel from user.
'***************************************************************************************************
'  promptStr = ""
'  defaultStr = ""
  Do While True
'     promptStr = promptStr & "Enter only the date (yymmdd) for the file you want to import."
'     promptStr = promptStr & vbNewLine & vbNewLine
'     promptStr = promptStr & "DO NOT enter file path or extention."
'     promptStr = promptStr & vbNewLine
     
'     inputDat = InputBox(promptStr, "Import File", defaultStr)
     inputDat = frmExtract.txtDay
     
     
'***************************************************************************************************
'If file is not found, inform user that entry does not exist
'***************************************************************************************************

     If inputDat = " " Then
        CSVFileDet = " "
        promptStr = CSVFileDet & vbNewLine
        promptStr = promptStr & "DOES NOT EXIST.  Enter Again."
        promptStr = promptStr & vbNewLine & vbNewLine
        defaultStr = inputDat
        Exit Do
     End If
     
     
     'FTP FILES
Dim txtUser, txtPass

txtUser = "ptms." & Trim(inputID)
txtPass = "" & Trim(InputPW)

    f = "C:\volume\temp\XFa9Tz0P.tmp"
    Open f For Output As #1
    Print #1, "open pmtdev"
    Print #1, txtUser
    Print #1, txtPass
    Print #1, "lcd c:\volume\"
    Print #1, "cd; 51#; sway"
    Print #1, "ascii"
    Print #1, "prompt"
    Print #1, "get VD" & Trim(inputDat); "c:\volume\" & "VD" & Trim(inputDat) & ".csv"
    Print #1, "get VS" & Trim(inputDat); "c:\volume\" & "VS" & Trim(inputDat) & ".csv"
    Print #1, "bye"
    Close #1
    Shell "c:\windows\system32\ftp.exe -s:C:\volume\temp\XFa9Tz0P.tmp"
    Open f For Output As #1
    Print #1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    Print #1, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
    Print #1, "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
    Print #1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    Print #1, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
    Print #1, "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
    Print #1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    Print #1, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
    Print #1, "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
    Print #1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    Print #1, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
    Print #1, "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
    Close #1
    Kill "C:\volume\temp\XFa9Tz0P.tmp"
   
   
'***************************************************************************************************
'Set variable "CSVFileDet" with user entered date
'***************************************************************************************************


     If inputDat = "" Then
        CSVFileDet = ""
        Exit Do
     Else
        CSVFileDet = "C:\Volume\VD" & Trim(inputDat) & ".csv" & ""
     End If

'***************************************************************************************************
'If "CSVFileDet" does not exist, inform user
'***************************************************************************************************

     If objDet.FileExists(CSVFileDet) Then
        Exit Do
     Else
        promptStr = CSVFileDet & vbNewLine
        promptStr = promptStr & "DOES NOT EXIST.  Enter Again."
        promptStr = promptStr & vbNewLine & vbNewLine
        defaultStr = inputDat
     End If
     
Loop


'***************************************************************************************************
'Search for VD + "inputDat" in the C:\Volume\ folder
'***************************************************************************************************

'ScreenUpdating = False
With Application.FileSearch
    .NewSearch
    .Filename = "VD" & Trim(inputDat) & ".csv"
    .LookIn = "C:\Volume\"
    .SearchSubFolders = False
   
'***************************************************************************************************
'If file is found, Execute
'***************************************************************************************************

    If .Execute() > 0 Then
   
        For i = 1 To .FoundFiles.Count
            PathInfo = .FoundFiles(i)
            MsgBox "" & .Filename & " File Located.... Importing File: " & Trim(inputDat) & ".csv"""
        Next i

'***************************************************************************************************
'Open .FoundFile(i)    **** .FoundFile(i) = Trim(inputDat).csv ] ****
'***************************************************************************************************
       
        Workbooks.Open Filename:=PathInfo
            ChDir "C:\Volume\"
           
           
   With Workbooks("VD" & Trim(inputDat) & ".csv").Sheets("VD" & Trim(inputDat))
      .UsedRange.Copy Workbooks("Vinnie." & Trim(InputWDat) & ".xls").Sheets(Trim(inputDay)).[A1].Resize(.UsedRange.Rows.Count, .UsedRange.Columns.Count)
   End With
'            Windows("VD070603.csv").Activate
'            Windows("VD" & Trim(inputDat) & ".csv").Activate
'            Sheets("VD" & Trim(inputDat) & "").Activate
'            Cells.Select
'            Selection.Copy

'            Windows("Vinnie." & Trim(InputWDat) & ".xls").Activate
'            Sheets("" & Trim(inputDay) & "").Select
'            Cells.Select
'            ActiveSheet.Paste

'            Cells.Select
'            Selection.Copy
'            Windows("Vinnie." & Trim(InputWDat) & ".xls").Activate
'            Sheets("" & Trim(inputDay) & "").Select
'            Cells.Select
'            ActiveSheet.Paste
'    ActiveWorkbook.SaveAs Filename:="C:\Volume\" & Trim(inputDat) & ".xls", FileFormat:=xlExcel5, _
'        Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
'        CreateBackup:=False
       
'***************************************************************************************************
'Format Detail Worksheet
'***************************************************************************************************

'    Windows("C:\Volume\" & Trim(inputDat) & ".xls").Activate
'    ActiveSheet.Name = "" & Trim(inputDat) & "_Detail" & ""
'    ActiveSheet.Columns("A:D").Select
'    ActiveSheet.Columns("A:D").EntireColumn.AutoFit
'    ActiveSheet.Range("A2").Select
'    ActiveWindow.FreezePanes = True
'    ActiveSheet.Range("A3").Select
'    ActiveWorkbook.Save
'    ActiveWorkbook.Close

'    Else
'        MsgBox "There were no files found."
    End If
   
End With

'***************************************************************************************************
'Search for VS + "inputDat" in the C:\Volume\ folder
'***************************************************************************************************

'With Application.FileSearch
'    .NewSearch
'    .Filename = "VS" & Trim(inputDat) & ".csv"
'    .LookIn = "C:\Volume\"
'    .SearchSubFolders = False
'
'***************************************************************************************************
'If file is found, Execute
'***************************************************************************************************
'
'    If .Execute() > 0 Then
'
'        For i = 1 To .FoundFiles.Count
'            PathInfo = .FoundFiles(i)
'            MsgBox "" & .Filename & " File Located.... Renaming & Importing File: " & NewNameS & ".csv"""
'        Next i
'        Workbooks.Open Filename:="C:\Volume\" & Trim(inputDat) & ".xls"
'            ChDir "C:\Volume\"
'    Sheets.Add
'    Sheets("Sheet1").Select
'    ActiveSheet.Name = "" & Trim(inputDat) & "_Summary" & ""
'
'    NewSheetName = ActiveSheet.Name
'    Else
'        MsgBox "There were no files found."
'    End If
'End With

    ActiveWorkbook.Save
'    ActiveWorkbook.Close
    Windows("VD" & Trim(inputDat) & ".csv").Activate
    ActiveWorkbook.Save
    ActiveWorkbook.Close
   

'***************************************************************************************************
'Import Summary CSV File
'***************************************************************************************************
'
'    With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Volume\" & Trim(InputDat) & ".csv", _
'        Destination:=Range("A1"))
'        .FieldNames = True
'        .RowNumbers = False
'        .FillAdjacentFormulas = False
'        .PreserveFormatting = True
'        .RefreshOnFileOpen = False
'        .RefreshStyle = xlInsertDeleteCells
'        .SavePassword = False
'        .SaveData = True
'        .AdjustColumnWidth = True
'        .RefreshPeriod = 0
'        .TextFilePromptOnRefresh = False
'        .TextFilePlatform = 437
'        .TextFileStartRow = 1
'        .TextFileParseType = xlDelimited
'        .TextFileTextQualifier = xlTextQualifierDoubleQuote
'        .TextFileConsecutiveDelimiter = False
'        .TextFileTabDelimiter = True
'        .TextFileSemicolonDelimiter = False
'        .TextFileCommaDelimiter = True
'        .TextFileSpaceDelimiter = False
'        .TextFileColumnDataTypes = Array(1, 1, 1, 1)
'        .TextFileTrailingMinusNumbers = True
'        .Refresh BackgroundQuery:=False
'    End With
       
'***************************************************************************************************
'Format Summary Worksheet
'***************************************************************************************************

'    ActiveSheet.Columns("A:D").Select
'    ActiveSheet.Columns("A:D").EntireColumn.AutoFit
'    ActiveSheet.Range("A2").Select
'    ActiveWindow.FreezePanes = True
'    ActiveSheet.Range("A3").Select
'    ActiveWorkbook.Save
'
'ScreenUpdating = True

End Sub

Private Sub cmdTID_Click()

    txtID.Visible = False
    lblTID.Visible = False
    lblTIDa.Visible = False
    cmdTID.Visible = False
    txtPW.Visible = True
    lblTPW.Visible = True
    cmdTPW.Visible = True

    frmExtract.Caption = "Tandem Password"
   
End Sub

Private Sub cmdTPW_Click()

    txtPW.Visible = False
    lblTPW.Visible = False
    cmdTPW.Visible = False
    txtWeek.Visible = True
    lblWeek.Visible = True
    lblWeeka.Visible = True
    cmdWeek.Visible = True

    frmExtract.Caption = "Starting Week Date"

End Sub

Private Sub cmdWeek_Click()

    txtWeek.Visible = False
    lblWeek.Visible = False
    lblWeeka.Visible = False
    cmdWeek.Visible = False
    txtDay.Visible = True
    lblDay.Visible = True
    lblDaya.Visible = True
    cmdDay.Visible = True
   
    frmExtract.Caption = "Day of Extract"

End Sub

My last post will work if both workbooks are open in the same Excel instance. Perhaps it's time to use the VBE debugger and inspect the workbook names you are generating. Make sure they match the actual workbook names exactly.

Kevin
Zorvek,

     I still can't get your submission to work.  I'm using a temporary fix using static names.  I will keep working on your submission and see if I can identify why it's not working.

If anyone has any suggestions, they will be greatly appreciated.

Thanks
Thanks Everyone for your assistance!!  

Rather than using dynamic names, I am still using static.  The purpose of the dynamic names, was to allo me to keep files for longer than 1 week and allow an archive to be created of files that were downloaded via FTP.  My workaround for my errors above is as follows.  Instead of downloading the files and attempting to import them based on their dynamic names, I am downloading the first file with a static name.  Additionally, I am downloading the first file again into a designated folder and downloading the second file into another designated folder.  If the folders do not exist, they are created.  Since the first file that is being downloaded on a T1 intranet and will never exeed 17kb, downloading it twice has virtually no impact on the code's performance.  After downloading the macro then imports the downloaded file to the correct sheet.  Once the import has been completed, the file downloaded and given a static name is deleted.

Below is the code I am using...



Option Explicit
Public VREXXDAT, VREXWDAT, VREXSDAY, VREXFDAY, VREXTID, VREXTPW, VRETID, VRETPS, VREDET, VREDDT, VRESDT, F

Private Sub cmdSave_Click()

'    ActiveWorkbook.Save
    frmVRE.Hide
    Unload frmVRE

End Sub

Sub UserForm_Initialize()

        txtVREIxD.SetFocus
   
End Sub

Private Sub cmdCancel_Click()

    frmVRE.Hide
    Unload frmVRE

End Sub

Private Sub cmdCancelCal_Click()

    frmVRE.Hide
    Unload frmVRE
   
End Sub


Private Sub cmdVREIxD_Click()

If txtVREIxD.Value = "" Then
        MsgBox "Please Enter Your Tandem ID"
        txtVREIxD.SetFocus
       
    Else

    If Left(LCase(txtVREIxD), 5) = "pmts." Then
        MsgBox "Please Remove PMTS. from your user ID."
        txtVREIxD.SetFocus
    Else
   
        VREXTID = txtVREIxD.Value
        txtVREIxD.Visible = False
        lblVREIxD.Visible = False
        lblVREIxDa.Visible = False
        cmdVREIxD.Visible = False
        txtVREPxW.Visible = True
        lblVREPxW.Visible = True
        cmdVREPxW.Visible = True
        txtVREPxW.SetFocus

        frmVRE.Caption = "Enter Tandem Password"
   
    End If
End If

End Sub

Private Sub cmdVREPxW_Click()

If txtVREPxW.Value = "" Then
        MsgBox "Please Enter Your Tandem PW"
        txtVREPxW.SetFocus
   
    Else

    VREXTPW = txtVREPxW.Value
    txtVREPxW.Visible = False
    lblVREPxW.Visible = False
    cmdVREPxW.Visible = False
    cmdCancel.Visible = False
    Cal1.Visible = True
    cmdOkCal.Visible = True
    cmdCancelCal.Visible = True
    frmVRE.Caption = "Select Extract Date"

End If

End Sub

Private Sub Cal1_Click()

    txt1.Value = Cal1.Value
    lblFile.Caption = Format(txt1.Value, "yymmdd")
    lblDay.Caption = Format(txt1.Value, "ddd")
   
    If lblDay.Caption = "Sun" Then
   
        lblWeekBegin.Caption = Format(txt1.Value, "yymmdd")
        VREXXDAT = lblFile.Caption
        VREXSDAY = "SUN"
        VREXWDAT = lblWeekBegin.Caption
        VREXFDAY = "Sunday"
       
    End If
   
    If lblDay.Caption = "Mon" Then
       
        lblWeekBegin.Caption = "0" & Format(txt1.Value, "yymmdd") - 1
        VREXXDAT = lblFile.Caption
        VREXSDAY = "MON"
        VREXWDAT = lblWeekBegin.Caption
        VREXFDAY = "Monday"
    End If
       
    If lblDay.Caption = "Tue" Then
       
        lblWeekBegin.Caption = "0" & Format(txt1.Value, "yymmdd") - 2
        VREXXDAT = lblFile.Caption
        VREXSDAY = "TUE"
        VREXWDAT = lblWeekBegin.Caption
        VREXFDAY = "Tuesday"
    End If

    If lblDay.Caption = "Wed" Then
       
        lblWeekBegin.Caption = "0" & Format(txt1.Value, "yymmdd") - 3
        VREXXDAT = lblFile.Caption
        VREXSDAY = "WED"
        VREXWDAT = lblWeekBegin.Caption
        VREXFDAY = "Wednesday"
    End If

    If lblDay.Caption = "Thu" Then
       
        lblWeekBegin.Caption = "0" & Format(txt1.Value, "yymmdd") - 4
        VREXXDAT = lblFile.Caption
        VREXSDAY = "THU"
        VREXWDAT = lblWeekBegin.Caption
        VREXFDAY = "Thursday"
    End If

    If lblDay.Caption = "Fri" Then
       
        lblWeekBegin.Caption = "0" & Format(txt1.Value, "yymmdd") - 5
        VREXXDAT = lblFile.Caption
        VREXSDAY = "FRI"
        VREXWDAT = lblWeekBegin.Caption
        VREXFDAY = "Friday"
    End If

    If lblDay.Caption = "Sat" Then
       
        lblWeekBegin.Caption = "0" & Format(txt1.Value, "yymmdd") - 6
        VREXXDAT = lblFile.Caption
        VREXSDAY = "SAT"
        VREXWDAT = lblWeekBegin.Caption
        VREXFDAY = "Saturday"
    End If
   
End Sub

Private Sub cmdOKCal_Click()

    Cal1.Visible = False
    cmdOkCal.Visible = False
    cmdCancelCal.Visible = False
    lblWork.Visible = True
   
    Continue
   
End Sub

 Sub Continue()

'***************************************************************************************************
'Create Folder with Week Beginning Date if it does not exist
'***************************************************************************************************

    If Dir("C:\Volume\Extracts\Detail\" & VREXWDAT & "\", vbDirectory) = "" Then
        MkDir ("C:\Volume\Extracts\Detail\" & VREXWDAT & "\")
    End If
   
    If Dir("C:\Volume\Extracts\Summary\" & VREXWDAT & "\", vbDirectory) = "" Then
        MkDir ("C:\Volume\Extracts\Summary\" & VREXWDAT & "\")
    End If


'***************************************************************************************************
'GET FTP FILES
'***************************************************************************************************

    VRETID = "pmts." & VREXTID
    VRETPS = VREXTPW
    VREDET = "VD" & VREXXDAT
    VREDDT = "VD" & VREXXDAT & ".csv"
    VRESDT = "VS" & VREXXDAT & ".csv"

    F = "C:\volume\temp\VREIMPRT.VRE"
    Open F For Output As #1
    Print #1, "open pmtdev"
    Print #1, VRETID
    Print #1, VRETPS
    Print #1, "lcd C:\Volume"
    Print #1, "cd " & " $data09"
    Print #1, "cd " & "volstats"
    Print #1, "ascii"
    Print #1, "prompt"
    Print #1, "get " & VREDET; " C:\volume\" & VREXFDAY & ".CSV"
    Print #1, "get " & VREDDT; " C:\Volume\Extracts\Detail\" & VREXWDAT & "\" & VREDDT
    Print #1, "get " & VRESDT; " C:\Volume\Extracts\Summary\" & VREXWDAT & "\" & VRESDT
    Print #1, "bye"
    Close #1
    Shell "C:\windows\system32\ftp.exe -s:C:\volume\temp\VREIMPRT.VRE"

'***************************************************************************************************
'ACTIVATE DAY OF WEEK SHEET.  IMPORT CSV TO DAY OF WEEK SHEET
'***************************************************************************************************

    If VREXSDAY = "SUN" Then
       Application.Wait Now + TimeValue("0:00:5")
       Sheets("SUN").Activate
       Get_Sunday
    Else
        If VREXSDAY = "MON" Then
           Application.Wait Now + TimeValue("0:00:5")
           Sheets("MON").Activate
           Get_Monday
        Else
            If VREXSDAY = "TUE" Then
               Application.Wait Now + TimeValue("0:00:5")
               Sheets("TUE").Activate
               Get_Tuesday
            Else
                If VREXSDAY = "WED" Then
                   Application.Wait Now + TimeValue("0:00:5")
                   Sheets("WED").Activate
                   Get_Wednesday
                Else
            If VREXSDAY = "THU" Then
               Application.Wait Now + TimeValue("0:00:5")
               Sheets("THU").Activate
               Get_Thursday
            Else
         If VREXSDAY = "FRI" Then
            Application.Wait Now + TimeValue("0:00:5")
            Sheets("FRI").Activate
            Get_Friday
         Else
    If VREXSDAY = "SAT" Then
       Application.Wait Now + TimeValue("0:00:5")
       Sheets("SAT").Activate
       Get_Saturday
    End If
   
End If
End If
End If
End If
End If
End If
   
End Sub


Sub DelFile()

Dim F

    F = "C:\volume\temp\VREIMPRT.VRE"
    Open F For Output As #1
    Print #1, "                                                                     ."
    Print #1, "                                                                    . "
    Print #1, "                                                                 . .. "
    Print #1, "                                          . .. ....  .       .. .~O7O$"
    Print #1, "                                         ..,DOZ?7,.  ..       ..?7NNON"
    Print #1, "                                       ...NNNNNNNNDO.. .    ....DINN8,"
    Print #1, "                                   ....$NNNNNNNNNNMNN8? .  .. . IDNND="
    Print #1, "                                   . INNMNNNNNNMNNMMNNNNN7.....78NN?NN"
    Print #1, "                          . .. . . INMMMNNMNNNNNNNMMNNNNNNN8NN8ODN? .:"
    Print #1, "                         ... .. INNMNMMNNMNMNNNNNNNNNNNNNNNNNNO8.... ."
    Print #1, "                         7IN.?,8NNMNNNNMNMMNNNNNNNNNNNNNN7NNNZ$D ...  "
    Print #1, "            . ... .  ... ONNNNNNNNNNNNNMNMNNNNNNNNNNMNNNZNNNNNNO.     "
    Print #1, "              ... ..$N? ,DO8DDNNNNNNNNMNNNNNNNNNNNNNNNNDNNNN~NNND...  "
    Print #1, "            ....~NNNNNNNNNNNNNDONNNNNNNNMNNNNNNNNNNNDNNNNNNNNNNMNN..  "
    Print #1, "          ...,NNNNNNNNNNNNMNNNNMNNNNNNNNNNNNNNNNNNNNNNDNNNNNNNNNNNN: ."
    Print #1, "        .  ,NNNNNMNMNNNMNNNNNNNNNMMMNNNNNNNNNNNNNDD88DNNNDNNMMNNNNNN? "
   
    Close #1
    Close #1
    Close #1
    Close #1

    Application.Wait Now + TimeValue("0:00:03")
   
    frmVRE.lblWork.Caption = "Saving..."
   
    If frmVRE.lblDay.Caption = "Sun" Then
        VREXFDAY = "Sunday"
    End If
    If frmVRE.lblDay.Caption = "Mon" Then
        VREXFDAY = "Monday"
    End If
    If frmVRE.lblDay.Caption = "Tue" Then
        VREXFDAY = "Tuesday"
    End If
    If frmVRE.lblDay.Caption = "Wed" Then
        VREXFDAY = "Wednesday"
    End If
    If frmVRE.lblDay.Caption = "Thu" Then
        VREXFDAY = "Thursday"
    End If
    If frmVRE.lblDay.Caption = "Fri" Then
        VREXFDAY = "Friday"
    End If
    If frmVRE.lblDay.Caption = "Sat" Then
        VREXFDAY = "Saturday"
    End If
   
    Kill "C:\Volume\" & VREXFDAY & ".CSV"
   
    Kill "C:\Volume\Temp\VREIMPRT.VRE"
           
    frmVRE.Hide
    Unload frmVRE

    ActiveWorkbook.Save
    Sheets("Total Summary").Activate


       
    End Sub
   
Sub Get_Sunday()

    With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Volume\Sunday.CSV", _
        Destination:=Range("A1"))
        .Name = "Sunday_2"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
   
    DelFile
   
End Sub
Sub Get_Monday()
   
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Volume\Monday.CSV", _
        Destination:=Range("A1"))
        .Name = "Monday"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
   
    DelFile
   
End Sub
Sub Get_Tuesday()
   
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Volume\Tuesday.CSV", _
        Destination:=Range("A1"))
        .Name = "Tuesday"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
   
    DelFile
   
End Sub
Sub Get_Wednesday()
   
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Volume\Wednesday.CSV", _
        Destination:=Range("A1"))
        .Name = "Wednesday"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
   
    DelFile
   
End Sub
Sub Get_Thursday()
   
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Volume\Thursday.CSV", _
        Destination:=Range("A1"))
        .Name = "Thursday"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
'        .Refresh BackgroundQuery:=False
    End With
   
    DelFile
   
End Sub
Sub Get_Friday()
   
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Volume\Friday.CSV", _
        Destination:=Range("A1"))
        .Name = "Friday"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
   
    DelFile
   
End Sub
Sub Get_Saturday()
   
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Volume\Saturday.CSV", _
        Destination:=Range("A1"))
        .Name = "Saturday"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
   
    DelFile
   
End Sub
Zorvek,

     I was able to get your last post to run successfully after I  posted my the current code I'm using above.  Since your submission worked, I'll award you the points.  I will however continue to use the "work-around" I poseted above.

Thanks Everyone.