Module Crashing Excel but Don't know why

hellfire45

Active Member
Joined
Jun 7, 2014
Messages
464
Hi guys so I have a module that is crashing excel every time and I don't know why. I will paste it below.
This path does not have two string variables declared; destinationpath and sourcepath

When I try to add the declarations (as seen below), then press f8 to step through the module, the workbook crashes.

The module is at it size limit and I can't see why.
I'm at a loss. Any ideas? Thanks!


Code:
dim destinationpath as string
dim sourcepath as string


Code:
Option Explicit

Sub build_template()
Dim fso As Object
Dim strTargetFile As String
Dim strFolder As String: strFolder = "I:\ASM\All\CRT\Reporting\In Consolidation Process\Reports\"
Dim strFileSpec As String: strFileSpec = strFolder & "*.*"
Dim strFileName As String
Dim destinationpath As String


Set fso = CreateObject("Scripting.FileSystemObject")


'sets the file path for key files
folderpath = "I:\ASM\All\CRT\Reporting\In Consolidation Process\Reports\"


'Builds folder directory with current date in report archive folder location seen below
If Dir("I:\ASM\All\CRT\Reporting\In Consolidation Process\Master Automation\Dated Report Archive\" & Format(Date, "yyyy-mm-dd"), vbDirectory) = "" Then
            MkDir ("I:\ASM\All\CRT\Reporting\In Consolidation Process\Master Automation\Dated Report Archive\" & Format(Date, "yyyy-mm-dd") & "\")
End If
destinationpath = "I:\ASM\All\CRT\Reporting\In Consolidation Process\Master Automation\Dated Report Archive\" & Format(Date, "yyyy-mm-dd") & "\"


SourcePath = "C:\Users\x\Desktop\y\Archive of XML\" & Format(Date, "yyyy-mm-dd") & "\"
strFileName = Dir(strFileSpec)




'big loop that processes the data from bout a dozen files and compile appends this data into "the hopper".
Do While strFileName <> ""
strExt = CreateObject("Scripting.FileSystemObject").GetExtensionName(strFileName)








End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You already have destinationpath declared. Other than that, I can't see a problem. That on its own would be nowhere near the limit for a module size.
 
Upvote 0
You already have destinationpath declared. Other than that, I can't see a problem. That on its own would be nowhere near the limit for a module size.

Sorry there was a type in there. It is NOT at its size limit as the module is nowhere near 64kb.

I just can't see why its crashing. Makes little sense to me.
 
Upvote 0
I do note that you haven't declared folderpath either, and your code won't compile as it is, since it is incomplete.
 
Upvote 0
I do note that you haven't declared folderpath either, and your code won't compile as it is, since it is incomplete.

Yes so the reason for that is because the minute i declare it, excel crashes. That's pretty much the whole issue in a nutshell.
 
Upvote 0
What I mean is that you should get a compile error as soon as you press f8 because that code can't run at all as it is written, even if you removed the Option Explicit statement. For instance, you have a Do While but no Loop line.
 
Upvote 0
What I mean is that you should get a compile error as soon as you press f8 because that code can't run at all as it is written, even if you removed the Option Explicit statement. For instance, you have a Do While but no Loop line.

I will post the entire script below. Sadly even with the loop commented out, excel crashes upon pressing f8 after i declare the sourcepath and folderpath as string

I don't understand why this is happening but its making me sad. lol.

Code:
Option Explicit

Sub build_template()
Dim fso As Object
Dim strTargetFile As String
Dim strFolder As String: strFolder = "I:\ASM\All\CRT\Reporting\In Consolidation Process\Reports\"
Dim strFileSpec As String: strFileSpec = strFolder & "*.*"
Dim strFileName As String
Dim destinationpath As String
Dim sourcepath As String
Dim folderpath As String






Set fso = CreateObject("Scripting.FileSystemObject")


'sets the file path for key files
folderpath = "I:\ASM\All\CRT\Reporting\In Consolidation Process\Reports\"


'Builds folder directory with current date in report archive folder location seen below
If Dir("I:\ASM\All\CRT\Reporting\In Consolidation Process\Master Automation\Dated Report Archive\" & Format(Date, "yyyy-mm-dd"), vbDirectory) = "" Then
            MkDir ("I:\ASM\All\CRT\Reporting\In Consolidation Process\Master Automation\Dated Report Archive\" & Format(Date, "yyyy-mm-dd") & "\")
End If
destinationpath = "I:\ASM\All\CRT\Reporting\In Consolidation Process\Master Automation\Dated Report Archive\" & Format(Date, "yyyy-mm-dd") & "\"


sourcepath = "C:\Users\jjoseph\Desktop\Cisco Project\Archive of XML\" & Format(Date, "yyyy-mm-dd") & "\"
strFileName = Dir(strFileSpec)




'big loop that processes the data from bout a dozen files and compile appends this data into "the hopper".
'Do While strFileName <> ""
'strExt = CreateObject("Scripting.FileSystemObject").GetExtensionName(strFileName)








End Sub
 
Upvote 0
Is that the entire content of the module? What happens if you Debug - Compile the project?
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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
Back
Top