A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Option Explicit
Sub CheckParserFile()
Dim sourcePath As String
Dim DirYear As Variant
Dim DirMonth As Variant
Dim ParserName As String
Dim ParserFile As String
Dim PromptString As String
Dim isfile As String
Dim PathName As String
Dim GotName As Boolean
Dim currentYear As Integer
Dim answer As String
Dim HomeDebug As Boolean
Dim User As String
Dim Marilyn As Integer
Const YearCell As String = "B7"
Const MonthCell As String = "B6"
Const NameCell As String = "B8"
HomeDebug = False
' First attempt at creating unique paths to parser file
If HomeDebug = True Then
PathName = "C:\Users\retir\OneDrive\Desktop\WTS\Column test\"
Else
User = VBA.Environ$("OneDrive") ' too many different profiles so we can't build this cleanly
Marilyn = InStr(VBA.Environ$("OneDrive"), "Marilyn") ' and Marily is a special case
If Marilyn = 0 Then
PathName = User & "\WTS Shared\Billing By Month\"
Else
PathName = User & "\Admin - WTS Shared\Billing By Month\"
End If
End If
' some debug statements
Range("A30").Value = "User Profile = " & VBA.Environ$("USERPROFILE")
Range("A31").Value = "OneDrive = " & VBA.Environ$("OneDrive")
Range("A32").Value = "user = " & Application.UserName
Range("A33").Value = "M check = " & Marilyn
Range("A34").Value = "Path = " & PathName
currentYear = Year(Date) ' Get the current year
'
' Get parser file name and then see if we can open it
'Get Month
DirMonth = ""
Sheets(UserSheet).Select
PromptString = "Please Enter Month "
DirMonth = Range(MonthCell).Value
While DirMonth = ""
If DirMonth = 0 Or DirMonth = "" Then
DirMonth = Application.InputBox(Prompt:=PromptString, Title:="Month")
End If
Wend
DirMonth = UCase(Left(DirMonth, 1)) & Mid(DirMonth, 2)
Range(MonthCell).Value = DirMonth
DirMonth = Trim(DirMonth)
'Get year
Nope: 'Get Year
PromptString = "Please Enter Year "
DirYear = Range(YearCell).Value
If Range(YearCell).Value = 0 Or Range(YearCell).Value = "" Then
DirYear = Application.InputBox(Prompt:=PromptString, Title:="Year")
DirYear = Trim(DirYear)
End If
If DirYear <> currentYear Then
answer = MsgBox("The year you entered is not the current year, is that what you want? ", vbQuestion + vbYesNo, "Current Year Validation")
If answer <> vbYes Then ' meaning no
DirYear = ""
Range(YearCell).Value = ""
GoTo Nope
End If
End If
Range(YearCell).Value = DirYear
' get Name
PromptString = "Please Enter the MailParser file name "
ParserFile = Range(NameCell).Value
While ParserFile = ""
If Range(NameCell).Value = 0 Or Range(NameCell).Value = "" Then
ParserFile = Application.InputBox(Prompt:=PromptString, Title:="MailParser File Name")
If ParserFile = "" Then ' this means the user wants to exit
AllDone = 1
GoTo fini
End If
End If
Wend
Range(NameCell).Value = ParserFile
ParserFile = Trim(ParserFile)
GotName = True
Do While GotName
ParserFile = PathName & DirMonth & " Billing\" & DirMonth & " " & DirYear & " Billing" & "\" & "Excel Files\" & ParserFile & ".xlsx"
sourcePath = ParserFile
If Left(sourcePath, 5) = "https" Then
PromptString = "Parser File not found, please re-enter"
Range("A28").Value = "Found https \*\*" & sourcePath & "\*\*"
GoTo BadFile
End If
isfile = Dir(sourcePath)
If isfile <> "" Then
Application.DisplayAlerts = False ' eliminate any issues with links that may need to be updated
On Error Resume Next
Workbooks.Open sourcePath ' Open parser file
On Error GoTo 0
GotName = False
Else
BadFile:
MsgBox ParserFile & " \*\*Does not exist\*\*"
PromptString = "Parser File Name"
ParserFile = Application.InputBox(Prompt:=PromptString, Title:="Parser File Name")
If ParserFile = "" Then ' this means the user wants to exit
AllDone = 1
GoTo fini
End If
End If
Loop
' now calling the mail parser routine to up load the data in the mail parser
Call CopyMailParser(sourcePath)
'Windows(sourcePath).Visible = True
fini:
If AllDone = 1 Then
MsgBox "User requested program termination", , "Code Closing Down"
End If
End Sub