VBA - code doesn't work in second macro

WesStewart

New Member
Joined
Aug 27, 2014
Messages
3
hey all, I'm pretty new to vba, and I could use some help
here is the code am using. This is just a basic macro to call another macro and loop. however, it seems to be skipping everything from "workbooks.open" through "activeworkbook.saveas"
the annoying bit is that I have used this code twice before but with different file names and paths and everything worked

I have stepped-through the code and it really just seems to be skipping those lines, which it does not do in the original code.

Any help would be greatly appreciated!

Code:
Sub oddball_macro_loop()
'
' oddball_macro_loop Macro
'
'

    Dim rawPath As String
    Dim rawFile As String
    Dim savePath As String
    Dim oWB As Workbook
    Dim fName As Variant
    
    
    rawPath = "I:\Cores\DMB\E-Prime Tasks\Salience Task\Data\Macros\Raw\For macro"
    rawFile = Dir(rawPath & "*.txt")
    savePath = "I:\Cores\DMB\E-Prime Tasks\Salience Task\Data\Macros\Processed"
    
    ChDir (rawPath)
    Application.DisplayAlerts = True
    
    Do While rawFile <> ""
        Workbooks.Open Filename:="I:\Cores\DMB\E-Prime Tasks\Salience Task\Data\Macros\oddball_macro.xlsm"
        Set oWB = Workbooks.Open(rawPath & rawFile)
        Application.Run "'oddball_macro.xlsm'!oddball_macro"
        Sheets("Data").Select
    
         
    'Sets File Name
        Dim text As String
        text = Range("Z12")
        fName = Mid(text, 19)
        ActiveWorkbook.SaveAs Filename:=savePath & fName, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
        ActiveWorkbook.Close False
        rawFile = Dir()
    Loop
    
    ActiveWorkbook.Close False
    Application.ScreenUpdating = True

    
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
When you stepped through the code, did it take you to 'oddball_macro'? I suspect that macro is not doing what you expect it to do, since there is nothing else in the posted macro that would do anything except select a sheet and save the file.
 
Upvote 0

WesStewart

New Member
Joined
Aug 27, 2014
Messages
3
When you stepped through the code, did it take you to 'oddball_macro'? I suspect that macro is not doing what you expect it to do, since there is nothing else in the posted macro that would do anything except select a sheet and save the file.

I should clarify. The issue is that the macro I am calling does not load at all. No error messages are given, it just seems to skip over those sections entirely when doing the step-into. When I have used other versions of this code, the step-into loads the other macro
 
Upvote 0

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
I should clarify. The issue is that the macro I am calling does not load at all. No error messages are given, it just seems to skip over those sections entirely when doing the step-into. When I have used other versions of this code, the step-into loads the other macro

I don't see anything wrong with the way the "oddball_macro" is called. You have opened the workbook it is in, so there should be no problem there. However, if all else fails, you can copy the procedure into the same workbook that you are now running the calling code from and modify the posted procedure to eliminate opening the oddball workbook and change the calling line to just:
Code:
oddball_macro
 
Upvote 0

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
85,187
Office Version
  1. 365
Platform
  1. Windows
ADVERTISEMENT
Hi
It looks as though both rawPath & savePath are missing a final \ should it be
Code:
    rawPath = "I:\Cores\DMB\E-Prime Tasks\Salience Task\Data\Macros\Raw\For macro\"
    rawFile = Dir(rawPath & "*.txt")
    savePath = "I:\Cores\DMB\E-Prime Tasks\Salience Task\Data\Macros\Processed\"
 
Upvote 0

WesStewart

New Member
Joined
Aug 27, 2014
Messages
3
Hi
It looks as though both rawPath & savePath are missing a final \ should it be
Code:
    rawPath = "I:\Cores\DMB\E-Prime Tasks\Salience Task\Data\Macros\Raw\For macro\"
    rawFile = Dir(rawPath & "*.txt")
    savePath = "I:\Cores\DMB\E-Prime Tasks\Salience Task\Data\Macros\Processed\"

That was it! thank you!
 
Upvote 0

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
85,187
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,195,990
Messages
6,012,723
Members
441,722
Latest member
tpaman1975

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top