Link to home
Start Free TrialLog in
Avatar of JaseSt
JaseStFlag for United States of America

asked on

changes to code worked on in previous, related question

The sheet name needs to be the same date as the file name. So, running the code today (12-27-2011) the sheet name should be 12-28-2011, the next business day.

Also, the Amount brought over from Col E in Visa Consolidated is not always in a two decimal format. (I know, you did not write that code.) However, when it is published to the sheet you just created, the amount brought into Col C needs to be formatted as currency with only 2 decimals, if possible.

One other point is that I'd really rather not have the newly created sheet saved in the Western Union folder. I try to keep things organized and separated. I already have the Access database there, which isn't where it use to be, and I'd rather not have this sheet in there as well.

It does NOT need to be a hardcoded location, but I'd prefer to not have to designate the place to save it  to every  time I open up the workbook
Avatar of Jacques Geday
Jacques Geday
Flag of Canada image

ok fine will do
gowflow
Avatar of JaseSt

ASKER

gowflwo, are you there?
yes had taken a break for ny !
gowflow
Avatar of JaseSt

ASKER

Thought so. A break well deserved, I'm sure.
yes I started with the question and made changes (quite a few) but then encountered errors and new year was around the corner so left it there. Will look at it asap
gowflow
Avatar of JaseSt

ASKER

gowflow, are we still a go with this? busy?
yes for sure sorry for the delay.
gowflow
ok JaseSt
First of all I am deeply sorry for the delay in providing you with the solution here as was caught with other issue together with the vacations of end year couple with the fact that when I started writing code for this question I had a sub that was dedicated to WU that needed adaptation.

Now when it comes to the solution:
1) Download the attached workbook that contains the Main sheet with its coding. You will need to replace the sheet Main in your Visa workbbok with the sheet in this workbook.

 Main.xlsm

2) Make a new copy of your latest Visa File and give it a new name.
3) Open the Visa File and do not activate Macros or make sure they are deactivated when you open the workbook.
4) Rename the current sheet Main in your Visa File to be 'Main old'.
5) open the Main.xlsm workbook hereattached from within the Visa file that is already opened.
6) Right click on the sheet Main (in the workbook you just opened) and choose Move or Copy and tick on Create a copy and in the top dropdown choose you visa workbook and click on the Sheet Main old so it places the sheet before Visa old. press ok
7) You should see now the Main then Main old in your visa workbook. SAVE the workbook and close the main.xlsm workbook without saving it as we do not need it at this stage anymore.

8) goto VBA and double click on ThisWorkbook in hte left pane.
9) Delete the whole code that is there by selecting Edit/select all then delete.
10) Paste the below code where you just deleted the code.

 
Private Sub Workbook_Deactivate() 'gstGenerateWUName
If gstFolderToMonitor <> "" Then SaveSetting APP_CATEGORY, APPNAME, "FolderToMonitor", gstFolderToMonitor
If gstFolderToTransfer <> "" Then SaveSetting APP_CATEGORY, APPNAME, "FolderToTransfer", gstFolderToTransfer
If gstFolderWesternUnion <> "" Then SaveSetting APP_CATEGORY, APPNAME, "FolderWesternUnion", gstFolderWesternUnion
If gstFolderVisaFile <> "" Then SaveSetting APP_CATEGORY, APPNAME, "FolderVisaFile", gstFolderVisaFile
If gstGenerateWUName <> "" Then SaveSetting APP_CATEGORY, APPNAME, "GenerateWUName", gstGenerateWUName
If gstGenerateWUEmail <> "" Then SaveSetting APP_CATEGORY, APPNAME, "GenerateWUEmail", gstGenerateWUEmail
End Sub

Private Sub Workbook_Open()
On Error GoTo errHandler

Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True

StartPGM = True
gstFolderToMonitor = GetSetting(APP_CATEGORY, APPNAME, "FolderToMonitor", vbNullString)
gstFolderToTransfer = GetSetting(APP_CATEGORY, APPNAME, "FolderToTransfer", vbNullString)
gstFolderWesternUnion = GetSetting(APP_CATEGORY, APPNAME, "FolderWesternUnion", vbNullString)
gstFolderVisaFile = GetSetting(APP_CATEGORY, APPNAME, "FolderVisaFile", vbNullString)
gstGenerateWUName = GetSetting(APP_CATEGORY, APPNAME, "GenerateWUName", vbNullString)
gstGenerateWUEmail = GetSetting(APP_CATEGORY, APPNAME, "GenerateWUEmail", vbNullString)


Set WSVisa = ThisWorkbook.Sheets("Wire-Staging-FBME")
Set wsMain = ThisWorkbook.Sheets("Main")

CRow = 1
wsMain.Range("L1:L1000").ClearContents
wsMain.Range("L" & CRow) = "Workbook Open - gstFolderToMonitor: " & gstFolderToMonitor
wsMain.Range("L" & CRow + 1) = "Workbook Open - gstFolderToTransfer: " & gstFolderToTransfer
wsMain.Range("L" & CRow + 2) = "Workbook Open - gstFolderWesternUnion: " & gstFolderWesternUnion
wsMain.Range("L" & CRow + 3) = "Workbook Open - gstFolderVisaFile: " & gstFolderVisaFile
wsMain.Range("L" & CRow + 4) = "Workbook Open - Last GenerateWUName: " & gstGenerateWUName
wsMain.Range("L" & CRow + 5) = "Workbook Open - Last GenerateWUEmail: " & gstGenerateWUEmail
CRow = CRow + 6

WSVisa.Activate
wsMain.Activate
Exit Sub

errHandler:
If Err = 9 Then
    MsgBox ("One of the essential sheets are missing. Pls review and try again")
    End
Else
    MsgBox (Error(Err))
    wsMain.Range("L" & CRow) = "Workbook Open - Error: <" & Error(Err) & ">"
    CRow = CRow + 1

    Resume Next
End If

End Sub

Open in new window


11) SAVE the workbook.
12) doubleclick on module1 and choose to view 1 sub at a time by clicking on the left bottom icon.
13) Delete the code that is in the General Decalration section and paste the below code after any End Sub.

 
Global Const APP_CATEGORY = "Software JG"
Global Const APPNAME = "ImportEmails"
Global WSVisa As Worksheet
Global wsMain As Worksheet

Global myolApp As Outlook.Application
Global gstFolderToMonitor As String
Global gstFolderToTransfer As String
Global gstFolderWesternUnion As String
Global gstFolderVisaFile As String
Global gstGenerateWUName As String
Global gstGenerateWUEmail As String
Global objOutlook As New Outlook.Application
Global objNameSpace As Outlook.Namespace
Global objFolders As Outlook.Folders
Global objFolder As MAPIFolder
Global InboxFolder As MAPIFolder

Global objFolderToMonitor As MAPIFolder
Global objFolderToTransfer As MAPIFolder

Global VisaItems As Outlook.Items
Global objMail As Outlook.MailItem
Global StartPGM As Boolean
Global CRow As Long

Open in new window


14) SAVE the workbook.
15) Select the Sub GenerateVisaFile and delete it.
16) Paste the below code after any End Sub.

 
Sub GenerateVisaFile()
Dim WS As Worksheet
Dim WSS As Worksheet
Dim NewWS As Worksheet
Dim MaxRow As Long, I As Long, J As Long, K As Long, DateCol As Long
Dim NewWb As Workbook
Dim NewWorkB As String
Dim TDate As String, Todate As Date, SDate As Date

If gstFolderVisaFile = "" Then
    MsgBox ("You need to select a destination folder to store the Create Visa File created. Please go to Sheet 'Main' and select a folder before proceeding further.")
    Exit Sub
Else
    If MsgBox("This process will create a new workbook with today's date and load in it all records in sheets 'Visa Consolidated' that bear today's date." & Chr(10) & Chr(10) _
        & "Are you ready to start this process ?", vbQuestion + vbYesNo, "Create Visa File") = vbYes Then
        
        Set WS = Sheets("Visa Consolidated")
        
        Set NewWb = Workbooks.Add
        Set NewWS = NewWb.Sheets("Sheet1")
        

        '---> Setup Next Date Visa file that should be on a working day
        '---> If Date is Saturday or Sunday it should go to Next Monday
        '---> or else on Next Day
        If Weekday(Now + 1) = 7 Then
            SDate = Now + 3
        Else
            If Weekday(Now + 1) = 1 Then
                SDate = Now + 2
            Else
                SDate = Now + 1
            End If
        End If
        
        NewWS.Name = Format(SDate, "mm-dd-yyyy")
        NewWb.SaveAs Filename:=gstFolderVisaFile & "Visa - Sovereign sm" & Format(SDate, "Mmmdd-yy") & ".xls", FileFormat:=xlExcel8
        NewWorkB = NewWb.Name
        

        
        J = 1
        K = 1
        'Date Col F
        DateCol = 6
        TDate = Format(Now, "mm/dd/yyyy")
        Todate = DateValue(TDate) + 1
        MaxRow = WS.UsedRange.Rows.Count
        WS.UsedRange.AutoFilter Field:=DateCol, Criteria1:=">=" & TDate, Operator:=xlAnd, Criteria2:="<" & Todate
        
        For I = 1 To MaxRow
            If WS.Range(I & ":" & I).EntireRow.Hidden = False Then
                
                If J = 1 Then
                    '---> Create the Header for the First Time
                    'Customer Identifier Currency    Amount  Merchant Reference
                    NewWS.Cells(J, "A") = "Customer Identifier"
                    NewWS.Cells(J, "B") = "Currency"
                    NewWS.Cells(J, "C") = "Amount"
                    NewWS.Cells(J, "D") = "Merchant Reference"
                    NewWS.Range(J & ":" & J).Font.Bold = True
                Else
                    '---> Copy Col B from Visa to Col A of New File
                    NewWS.Cells(J, "A") = WS.Cells(I, "B")
                    
                    '---> Copy Col E from Visa to Col C of New File
                    NewWS.Cells(J, "C") = Format(WS.Cells(I, "E"), "€#,###.00")
                    
                    '---> Put EUR to Col B of New File
                    NewWS.Cells(J, "B") = "EUR"
                    
                    '---> Insert 'smcurrentYearMonthDate#' Visa to Col D of New File
                    NewWS.Cells(J, "D") = "sm" & Format(Year(SDate), "0000") & Format(Month(SDate), "00") & Format(Day(SDate), "00") & J - 1
                End If
                J = J + 1
            End If
        Next I
        WS.ShowAllData
        WS.AutoFilterMode = False
       
        With NewWS.Columns("A:D")
           .EntireColumn.AutoFit
           .HorizontalAlignment = xlCenter
        End With
           
        Application.DisplayAlerts = False
        
        For Each WSS In NewWb.Worksheets
            If WSS.Name <> NewWS.Name Then WSS.Delete
        Next WSS
        
        
        NewWb.Save
        
        'Set NewWb = Nothing
        'Set NewWS = Nothing
        Application.DisplayAlerts = True
        
        'ws.Activate
        MsgBox ("Workbook: '" & NewWorkB & "' has been created successfully")
          
        
    End If
End If
End Sub

Open in new window


17) SAVE the workbook and exit.
18) Restart it and activate macros. You should be prompt to find a location for the Visa File or the WU file also pls select the appropriate folders that you wish to save data to for both and once done save the workbook and close it. Restart it again and you should not be prompt anymore to find a location unless you activate the commandbutton and wishes to change location.
19) Give it a try for Generate Visa file and check if all what you wanted has been done.

NOTE
If there are some Sub that other Experts have developped and that are linked to command buttons in sheet Main then you will need to put them again let me know and will check in the sheet Main old where the problem is and will fix it.

gowflow
Avatar of JaseSt

ASKER

Wow! What a lot of work this entailed!!
I'll implement it and give it a try in a few hours.
Hey gowflow, I can hardly complain about any of the work you do for me.
Just wondering if you were still wanting to do it, that's all.
I'll get back to you.
Thank you.
Yes no problem, but as it is for free it will have sometimes to wait for other priorities. Now if you are willing to treat this on the Hire Me basis then for sure you will get a diffrent result.
gowflow
Avatar of JaseSt

ASKER

Followed directions, but when opening the new Visa file with your Main sheet now included I get an error:

Invalid procedure call or argument. I click OK and get: Run-time error 424: Object required. Click on Debug and get this line highlighted in yellow:

wsMain.Range("L" & CRow) = "Workbook Open - Error: <" & Error(Err) & ">"

Not sure what I should do next.
Avatar of JaseSt

ASKER

Also, when clicking on the Cross Check Visa w Database button, get a message that it could not find the database, but it is looking in the Visa\VisaLoadRequests folder. I've had it in the Western Union folder
yes if you open the file I posted you will get an error if the macros are active you should as I said disable macros first then open the file all these errors are meaningless.
to disable macros click on the office button on top left corner of excel then choose Excel options then click on Trsut Center then click on Trsut Center Settings then click on Macro Settings and then choose second option Disable Macros with notification press ok twice exit and now load the file and follow the instructions.

 User generated image
gowflow
Any news ?
gowflow
Avatar of JaseSt

ASKER

Did all that, but whenever I go to the Main sheet I get the below error. When I go to the Main Old sheet or any other sheet there is no problem, just when I go to the Main sheet.

Compile error: Wrong number of arguments or invalid property assignment. I click OK  and GetNewFolder is selected (not highlighted in yellow)

When I click on the Choose Location to save Western Union File created this code is highlighted in yellow: Private Sub CommandButton3_Click()

When I click on the Choose Location to Ssave Visa File created, I get this yellow highlighted code:
Private Sub CommandButton11_Click()
so let me recap here
1) you disabled macros
2) downloaded the attached file on your pc
3) saved a new copy of your latest visa under a new name
4) opened the new visa file with macros disabled.
5) from within visa you opened the dowloaded file
6) positioned yourself in the downloaded file and copied the Main sheet to visa file (it should warn you with macro security or something at this point you should say accept or enable so it copies the whole code

pls confirm you did that
gowflow
Avatar of JaseSt

ASKER

I'll go through it again, closing all  other spreadsheets first.
yes please as I feel you are trying to ride 16 horses at the same time !!!! always this issue with you !!
:)
gowflow
Avatar of JaseSt

ASKER

1) you disabled macros - yes
2) downloaded the attached file on your pc - yes
3) saved a new copy of your latest visa under a new name - yes
4) opened the new visa file with macros disabled. - yes
5) from within visa you opened the dowloaded file -yes
6) positioned yourself in the downloaded file and copied the Main sheet to visa file (it should warn you with macro security or something at this point you should say accept or enable so it copies the whole code- yes, but then get a compile error: Wrong number of arguments or invalid property assignment. I click OK and 'GetNewFolder' is selected (not highlighted in yellow)
Avatar of JaseSt

ASKER

and then

When I click on the Choose Location to save Western Union File created this code is highlighted in yellow: Private Sub CommandButton3_Click()

When I click on the Choose Location to Ssave Visa File created, I get this yellow highlighted code:
Private Sub CommandButton11_Click()
ok seems it is meesed up some where no worry will fix it. Provided you copied the whole code as indicated in my original post I think the only problem left is the code with sheet main so do the following.

1) open the Visa file that contain the error and all the other modules that were loaded form my post.
2) goto vba
3) doubleclick on sheet Main in the left pane and choose from the edit menu Select All and press on delete it should delete the whole code that is in sheet Main.
4) Copy the below code and paste it in sheet Main.

 
Private Sub Combobox1_Change()
gstFolderToMonitor = ComboBox1.Text
If ComboBox1 <> "" And ComboBox2 <> "" Then
    CommandButton1.Enabled = True
Else
    CommandButton1.Enabled = False
End If
wsMain.Range("L" & CRow) = "Combo1 Change - " & gstFolderToMonitor
CRow = CRow + 1

End Sub

Private Sub ComboBox2_Change()
gstFolderToTransfer = ComboBox2.Text

If ComboBox1 <> "" And ComboBox2 <> "" Then
    CommandButton1.Enabled = True
Else
    CommandButton1.Enabled = False
End If
wsMain.Range("L" & CRow) = "Combo2 Change - " & gstFolderToTransfer
CRow = CRow + 1
End Sub

Private Sub CommandButton1_Click()
'GetEmails
LocateEmails
End Sub

Private Sub CommandButton10_Click()
GenerateVisaFile
End Sub

Private Sub CommandButton11_Click()
gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

End Sub

Private Sub CommandButton2_Click()
ImportWesternUnion
End Sub

Private Sub CommandButton3_Click()
gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"

End Sub

Private Sub CommandButton4_Click()
WMFileCreate Sheets("WU-Staging-FBME")
End Sub

Private Sub CommandButton5_Click()
If gstGenerateWUName = "" Then
    MsgBox ("You should Run command [Generate WU File] first, as no file has been generated yet.")
Else
    If gstGenerateWUName = gstGenerateWUEmail Then
        MsgBox ("File : '" & gstGenerateWUEmail & "' has already been emailed. You should Run command [Generate WU File] to create a new file.")
    Else
        If gstGenerateWUName <> "" And gstGenerateWUEmail = "" Then
            WUEmailCreate Sheets("WU-Staging-FBME"), gstGenerateWUName
        End If
    End If
End If
End Sub

Private Sub CommandButton6_Click()
ImportWUConfirmedAmts
End Sub

Private Sub CommandButton7_Click()
Dim SDate As String
Do
    SDate = InputBox("Please Enter Start Date for beginning tracking WU Balance", "Start Date", "10/18/2011")
Loop Until IsDate(SDate) Or SDate = ""

If SDate <> "" Then
    UpdateWUBalance SDate
End If
End Sub

Private Sub CommandButton8_Click()
LocateEmailsToTabsNew
End Sub

Private Sub CommandButton9_Click()
CrossCheckVisaAndDB
End Sub

Private Sub Worksheet_Activate()
On Error GoTo ErrhandlerAct

If StartPGM Then
    FillCombo ComboBox1
    FillCombo ComboBox2
    
    gstFolderToMonitor = ComboBox1
    gstFolderToTransfer = ComboBox2
    
    If gstFolderToMonitor = "" Then
        MsgBox ("Please select a Folder to Monitor Emails")
    Else
        ComboBox1.Text = gstFolderToMonitor
    End If
    
    If gstFolderToTransfer = "" Then
        MsgBox ("Please select a Folder to Transfer Emails Imported")
    Else
        ComboBox2.Text = gstFolderToTransfer
    End If
    
    If ComboBox1 <> "" And ComboBox2 <> "" And gstFolderToMonitor <> "" And gstFolderToTransfer <> "" Then
        CommandButton1.Enabled = True
    Else
        CommandButton1.Enabled = False
    End If
    
    If gstFolderWesternUnion = vbNullString Then
    gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
    End If
    Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"
        
    If gstFolderVisaFile = vbNullString Then
    gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
    End If
    Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

    
    If gstGenerateWUName <> gstGenerateWUEmail Then
        MsgBox ("Please note that File : '" & gstGenerateWUName & "' has been created, however not Emailed." & Chr(10) & Chr(10) _
            & "You should proceed to select [Generate Email & Update 'WU-Staging-FBME'] button to Email the created file." & Chr(10) & Chr(10) _
            & "You may at any time, select [Generate WU File] to build a new file for Export")
    End If
    
    wsMain.Range("L" & CRow) = "Main Activate - gstFolderToMonitor: " & gstFolderToMonitor
    wsMain.Range("L" & CRow + 1) = "Main Activate - gstFolderToTransfer: " & gstFolderToTransfer
    wsMain.Range("L" & CRow + 2) = "Main Activate - gstFolderWesternUnion: " & gstFolderWesternUnion
    wsMain.Range("L" & CRow + 3) = "Main Activate - gstFolderVisaFile: " & gstFolderVisaFile
    CRow = CRow + 4
    StartPGM = False
End If

Exit Sub

ErrhandlerAct:
MsgBox (Error(Err))
Resume Next

End Sub

Open in new window


5) SAVE the workbook and exit
6) Start the workbook and activate macros and check it out.

gowflow
Avatar of JaseSt

ASKER

Still get the errors.

I'm going to try this one more time, making sure that each step is followed and I will tell you what I did in order and then the results.
Avatar of JaseSt

ASKER

Downloaded and saved Main.xlsm, then closed excel
Open Excel turn off macros, exit excel.
Open original Visa workbook
Renamed Main to Main old
From within Visa spreadsheet open your Main.xlsm
Copied your Main sheet to my Visa spreadsheet, placing it before Main old
Saved Visa workbook
Close Main.xlsm
Open VBA click on ThisWorkbook, deleted all code and replaced it with yours
Saved workbook
Went to Module 1
Deleted General Declarations replacing it with your code after an End Sub
Saved
Deleted GenerateVisaFile Sub, replacing it with yours
Deleted all code in Main, replacing it with your new code from comment 37406847
Saved and exited Excel
Restart excel, enable macros
Reopen updated Visa workbook
Give me an error: Invalid procedure call or argument
Going to debug this line in highlighted in yellow:
wsMain.Range("L" & CRow) = "Workbook Open - Error: <" & Error(Err) & ">"
End debug

Click on Find location.

When I click on the Choose Location to save Western Union File created this code is highlighted in yellow: Private Sub CommandButton3_Click()

When I click on the Choose Location to Ssave Visa File created, I get this yellow highlighted code:
Private Sub CommandButton11_Click()
Just thought of something maybe when you rename Main to Main old it is still somewhow using it when accessing try delete this sheet altogether from the workbook and also delete the whole code that is in sheet main and re paste the Main code save and try it again.
gowflow
Avatar of JaseSt

ASKER

Don't think that is it, but will try. Errors or messages pop up immediately when I copy Main to the workbook. Let you know in a few secs.
Avatar of JaseSt

ASKER

Nope. Deleting Main old doesn't change anything. Whenever I click on the new Main sheet tab (when on another sheet) I get the compile error message with 'Private Sub Worksheet_Activate()' highlighted in yellow.
delete all the code in Main save the workbook exit the workbook open it again and see if the error is there. It should not.
if no error then goto vba doubleclick on Main you should have no code there select all form the below code right click copy and paste in Main save the workbook exit restart again and try it.
gowflow
Private Sub Worksheet_Activate()
On Error GoTo ErrhandlerAct

If StartPGM Then
    FillCombo ComboBox1
    FillCombo ComboBox2
    
    gstFolderToMonitor = ComboBox1
    gstFolderToTransfer = ComboBox2
    
    If gstFolderToMonitor = "" Then
        MsgBox ("Please select a Folder to Monitor Emails")
    Else
        ComboBox1.Text = gstFolderToMonitor
    End If
    
    If gstFolderToTransfer = "" Then
        MsgBox ("Please select a Folder to Transfer Emails Imported")
    Else
        ComboBox2.Text = gstFolderToTransfer
    End If
    
    If ComboBox1 <> "" And ComboBox2 <> "" And gstFolderToMonitor <> "" And gstFolderToTransfer <> "" Then
        CommandButton1.Enabled = True
    Else
        CommandButton1.Enabled = False
    End If
    
    If gstFolderWesternUnion = vbNullString Then
    gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
    End If
    Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"
        
    If gstFolderVisaFile = vbNullString Then
    gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
    End If
    Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

    
    If gstGenerateWUName <> gstGenerateWUEmail Then
        MsgBox ("Please note that File : '" & gstGenerateWUName & "' has been created, however not Emailed." & Chr(10) & Chr(10) _
            & "You should proceed to select [Generate Email & Update 'WU-Staging-FBME'] button to Email the created file." & Chr(10) & Chr(10) _
            & "You may at any time, select [Generate WU File] to build a new file for Export")
    End If
    
    wsMain.Range("L" & CRow) = "Main Activate - gstFolderToMonitor: " & gstFolderToMonitor
    wsMain.Range("L" & CRow + 1) = "Main Activate - gstFolderToTransfer: " & gstFolderToTransfer
    wsMain.Range("L" & CRow + 2) = "Main Activate - gstFolderWesternUnion: " & gstFolderWesternUnion
    wsMain.Range("L" & CRow + 3) = "Main Activate - gstFolderVisaFile: " & gstFolderVisaFile
    CRow = CRow + 4
    StartPGM = False
End If

Exit Sub

ErrhandlerAct:
MsgBox (Error(Err))
Resume Next

End Sub

Open in new window

Avatar of JaseSt

ASKER

With no code it produced no error. When placing the above code in main it came up with the same error on start up with 'Private Sub Worksheet_Activate()' highlighted in yellow.
and what is the error ? what does it say snapshot please Am stunned !!! only they happen with you
gowflow
just curious when you did

Downloaded and saved Main.xlsm, then closed excel
Open Excel turn off macros, exit excel.
Open original Visa workbook
Renamed Main to Main old
From within Visa spreadsheet open your Main.xlsm
Copied your Main sheet to my Visa spreadsheet, placing it before Main old

once you got to this stage it should pop up a screen saying Enable macro or Disable potential security risk what did you answer ?? You should answer Enable !!!

gowflow
Avatar of JaseSt

ASKER

When I click on the Main tab, get the attached errors User generated image User generated image
Happens every time I click on the tab Main if I am on another sheet.
Avatar of JaseSt

ASKER

In answer to your last question, the answer is yes. The warning came up and I enabled.
Shame on me !! you mentioned it before but as I did not see the error it did not dowan on me.
:(
goto vba module1 choose 1 sub at a time and delete Sub GetNewFolder and replace it by the below code.

Extreemly sorry this time surely and positively entirely my fault !!! Air head !
gowflow
Function GetNewFolder(fFolder As String, Title As String)

fFolder = GFolderName(Title)

If fFolder <> "" And Dir(fFolder) <> "" Then
    GetNewFolder = fFolder
Else
    MsgBox ("No Folder has been selected or the Folder does not exist, therefore data cannot be Exported" _
        & " until valid Folder has been selected." & Chr(10) & Chr(10) _
        & "Please press on the command bar to choose a Folder.")
    GetNewFolder = "Browse"

    With Application
        .DisplayAlerts = True
        .EnableEvents = True
    End With
    
    Exit Function
End If
End Function

Open in new window

Avatar of JaseSt

ASKER

This time no errors on opening or on clicking on Main tab, however, I cannot seem to change the location for Western Union File or Visa File location. When I click on the pink bars, nothing happens. When I click on the Generate Visa File button, nothing happens.

Exiting Excel and restarting workbook does not change the above results.
pls goto developper menu and click on Design and doubleclick on the Generate Visa File button and paste here what code it is showing pls
gowlfow
Sorry it is past midnite here if you need assistance on this now pls advise
gowflow
Avatar of JaseSt

ASKER

Looks like I was supposed to put a code behind this button. Let me look up in your previous posts. Maybe I missed something. User generated image
Avatar of JaseSt

ASKER

Now that's interesting. I didn't copy the code from your Main sheet to the Main code when I imported. Was I supposed to do that? Must have missed that step, because your Main code looks completely different than mine.
well what do you have now what sheet ? pls delete all the code in Main delete Main old and copy this code in Main
gowflow
Private Sub Combobox1_Change()
gstFolderToMonitor = ComboBox1.Text
If ComboBox1 <> "" And ComboBox2 <> "" Then
    CommandButton1.Enabled = True
Else
    CommandButton1.Enabled = False
End If
wsMain.Range("L" & CRow) = "Combo1 Change - " & gstFolderToMonitor
CRow = CRow + 1

End Sub

Private Sub ComboBox2_Change()
gstFolderToTransfer = ComboBox2.Text

If ComboBox1 <> "" And ComboBox2 <> "" Then
    CommandButton1.Enabled = True
Else
    CommandButton1.Enabled = False
End If
wsMain.Range("L" & CRow) = "Combo2 Change - " & gstFolderToTransfer
CRow = CRow + 1
End Sub

Private Sub CommandButton1_Click()
'GetEmails
LocateEmails
End Sub

Private Sub CommandButton10_Click()
GenerateVisaFile
End Sub

Private Sub CommandButton11_Click()
gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

End Sub

Private Sub CommandButton2_Click()
ImportWesternUnion
End Sub

Private Sub CommandButton3_Click()
gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"

End Sub

Private Sub CommandButton4_Click()
WMFileCreate Sheets("WU-Staging-FBME")
End Sub

Private Sub CommandButton5_Click()
If gstGenerateWUName = "" Then
    MsgBox ("You should Run command [Generate WU File] first, as no file has been generated yet.")
Else
    If gstGenerateWUName = gstGenerateWUEmail Then
        MsgBox ("File : '" & gstGenerateWUEmail & "' has already been emailed. You should Run command [Generate WU File] to create a new file.")
    Else
        If gstGenerateWUName <> "" And gstGenerateWUEmail = "" Then
            WUEmailCreate Sheets("WU-Staging-FBME"), gstGenerateWUName
        End If
    End If
End If
End Sub

Private Sub CommandButton6_Click()
ImportWUConfirmedAmts
End Sub

Private Sub CommandButton7_Click()
Dim SDate As String
Do
    SDate = InputBox("Please Enter Start Date for beginning tracking WU Balance", "Start Date", "10/18/2011")
Loop Until IsDate(SDate) Or SDate = ""

If SDate <> "" Then
    UpdateWUBalance SDate
End If
End Sub

Private Sub CommandButton8_Click()
LocateEmailsToTabsNew
End Sub

Private Sub CommandButton9_Click()
CrossCheckVisaAndDB
End Sub

Private Sub Worksheet_Activate()
On Error GoTo ErrhandlerAct

If StartPGM Then
    FillCombo ComboBox1
    FillCombo ComboBox2
    
    gstFolderToMonitor = ComboBox1
    gstFolderToTransfer = ComboBox2
    
    If gstFolderToMonitor = "" Then
        MsgBox ("Please select a Folder to Monitor Emails")
    Else
        ComboBox1.Text = gstFolderToMonitor
    End If
    
    If gstFolderToTransfer = "" Then
        MsgBox ("Please select a Folder to Transfer Emails Imported")
    Else
        ComboBox2.Text = gstFolderToTransfer
    End If
    
    If ComboBox1 <> "" And ComboBox2 <> "" And gstFolderToMonitor <> "" And gstFolderToTransfer <> "" Then
        CommandButton1.Enabled = True
    Else
        CommandButton1.Enabled = False
    End If
    
    If gstFolderWesternUnion = vbNullString Then
    gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
    End If
    Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"
        
    If gstFolderVisaFile = vbNullString Then
    gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
    End If
    Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

    
    If gstGenerateWUName <> gstGenerateWUEmail Then
        MsgBox ("Please note that File : '" & gstGenerateWUName & "' has been created, however not Emailed." & Chr(10) & Chr(10) _
            & "You should proceed to select [Generate Email & Update 'WU-Staging-FBME'] button to Email the created file." & Chr(10) & Chr(10) _
            & "You may at any time, select [Generate WU File] to build a new file for Export")
    End If
    
    wsMain.Range("L" & CRow) = "Main Activate - gstFolderToMonitor: " & gstFolderToMonitor
    wsMain.Range("L" & CRow + 1) = "Main Activate - gstFolderToTransfer: " & gstFolderToTransfer
    wsMain.Range("L" & CRow + 2) = "Main Activate - gstFolderWesternUnion: " & gstFolderWesternUnion
    wsMain.Range("L" & CRow + 3) = "Main Activate - gstFolderVisaFile: " & gstFolderVisaFile
    CRow = CRow + 4
    StartPGM = False
End If

Exit Sub

ErrhandlerAct:
MsgBox (Error(Err))
Resume Next

End Sub

Open in new window

Avatar of JaseSt

ASKER

While I can now use the buttons to correctly select the location of Visa and Western Union files, the other buttons (the Import WU email, Import Emails to Tabs) are not working, giving me the message that an object could not be found and Monitor folder is invalid.
wow !!! lets revert to a manual installation I did all that the avoid manual installation but seems we will need to do that.

1) Take your latest 'working visa file' the one that was ok prior to this last installation (the one we performed first in this question like take the file that was ok before this question) give it a new name
2) goto VBA and double click on ThisWorkbook in the left pane.
3) Delete the whole code that is there by selecting Edit/select all then delete.
4) Paste the below code where you just deleted the code in Thisworkbook

 
Private Sub Workbook_Deactivate() 'gstGenerateWUName
If gstFolderToMonitor <> "" Then SaveSetting APP_CATEGORY, APPNAME, "FolderToMonitor", gstFolderToMonitor
If gstFolderToTransfer <> "" Then SaveSetting APP_CATEGORY, APPNAME, "FolderToTransfer", gstFolderToTransfer
If gstFolderWesternUnion <> "" Then SaveSetting APP_CATEGORY, APPNAME, "FolderWesternUnion", gstFolderWesternUnion
If gstFolderVisaFile <> "" Then SaveSetting APP_CATEGORY, APPNAME, "FolderVisaFile", gstFolderVisaFile
If gstGenerateWUName <> "" Then SaveSetting APP_CATEGORY, APPNAME, "GenerateWUName", gstGenerateWUName
If gstGenerateWUEmail <> "" Then SaveSetting APP_CATEGORY, APPNAME, "GenerateWUEmail", gstGenerateWUEmail
End Sub

Private Sub Workbook_Open()
On Error GoTo errHandler

Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True

StartPGM = True
gstFolderToMonitor = GetSetting(APP_CATEGORY, APPNAME, "FolderToMonitor", vbNullString)
gstFolderToTransfer = GetSetting(APP_CATEGORY, APPNAME, "FolderToTransfer", vbNullString)
gstFolderWesternUnion = GetSetting(APP_CATEGORY, APPNAME, "FolderWesternUnion", vbNullString)
gstFolderVisaFile = GetSetting(APP_CATEGORY, APPNAME, "FolderVisaFile", vbNullString)
gstGenerateWUName = GetSetting(APP_CATEGORY, APPNAME, "GenerateWUName", vbNullString)
gstGenerateWUEmail = GetSetting(APP_CATEGORY, APPNAME, "GenerateWUEmail", vbNullString)


Set WSVisa = ThisWorkbook.Sheets("Wire-Staging-FBME")
Set wsMain = ThisWorkbook.Sheets("Main")

CRow = 1
wsMain.Range("L1:L1000").ClearContents
wsMain.Range("L" & CRow) = "Workbook Open - gstFolderToMonitor: " & gstFolderToMonitor
wsMain.Range("L" & CRow + 1) = "Workbook Open - gstFolderToTransfer: " & gstFolderToTransfer
wsMain.Range("L" & CRow + 2) = "Workbook Open - gstFolderWesternUnion: " & gstFolderWesternUnion
wsMain.Range("L" & CRow + 3) = "Workbook Open - gstFolderVisaFile: " & gstFolderVisaFile
wsMain.Range("L" & CRow + 4) = "Workbook Open - Last GenerateWUName: " & gstGenerateWUName
wsMain.Range("L" & CRow + 5) = "Workbook Open - Last GenerateWUEmail: " & gstGenerateWUEmail
CRow = CRow + 6

WSVisa.Activate
wsMain.Activate
Exit Sub

errHandler:
If Err = 9 Then
    MsgBox ("One of the essential sheets are missing. Pls review and try again")
    End
Else
    MsgBox (Error(Err))
    wsMain.Range("L" & CRow) = "Workbook Open - Error: <" & Error(Err) & ">"
    CRow = CRow + 1

    Resume Next
End If

End Sub

Open in new window


5) SAVE the workbook.
6) doubleclick on module1 and choose left bottom icon to view 1 sub at a time.
7) You should have the declaration section module delete it
8) Select the Sub GenerateVisaFile and delete it. Select Sub GetNewFolder  and delete it.
9) Paste the below code after any end sub


 
Global Const APP_CATEGORY = "Software JG"
Global Const APPNAME = "ImportEmails"
Global WSVisa As Worksheet
Global wsMain As Worksheet

Global myolApp As Outlook.Application
Global gstFolderToMonitor As String
Global gstFolderToTransfer As String
Global gstFolderWesternUnion As String
Global gstFolderVisaFile As String
Global gstGenerateWUName As String
Global gstGenerateWUEmail As String
Global objOutlook As New Outlook.Application
Global objNameSpace As Outlook.Namespace
Global objFolders As Outlook.Folders
Global objFolder As MAPIFolder
Global InboxFolder As MAPIFolder

Global objFolderToMonitor As MAPIFolder
Global objFolderToTransfer As MAPIFolder

Global VisaItems As Outlook.Items
Global objMail As Outlook.MailItem
Global StartPGM As Boolean
Global CRow As Long

Sub GenerateVisaFile()
Dim WS As Worksheet
Dim WSS As Worksheet
Dim NewWS As Worksheet
Dim MaxRow As Long, I As Long, J As Long, K As Long, DateCol As Long
Dim NewWb As Workbook
Dim NewWorkB As String
Dim TDate As String, Todate As Date, SDate As Date

If gstFolderVisaFile = "" Then
    MsgBox ("You need to select a destination folder to store the Create Visa File created. Please go to Sheet 'Main' and select a folder before proceeding further.")
    Exit Sub
Else
    If MsgBox("This process will create a new workbook with today's date and load in it all records in sheets 'Visa Consolidated' that bear today's date." & Chr(10) & Chr(10) _
        & "Are you ready to start this process ?", vbQuestion + vbYesNo, "Create Visa File") = vbYes Then
        
        Set WS = Sheets("Visa Consolidated")
        
        Set NewWb = Workbooks.Add
        Set NewWS = NewWb.Sheets("Sheet1")
        

        '---> Setup Next Date Visa file that should be on a working day
        '---> If Date is Saturday or Sunday it should go to Next Monday
        '---> or else on Next Day
        If Weekday(Now + 1) = 7 Then
            SDate = Now + 3
        Else
            If Weekday(Now + 1) = 1 Then
                SDate = Now + 2
            Else
                SDate = Now + 1
            End If
        End If
        
        NewWS.Name = Format(SDate, "mm-dd-yyyy")
        NewWb.SaveAs Filename:=gstFolderVisaFile & "Visa - Sovereign sm" & Format(SDate, "Mmmdd-yy") & ".xls", FileFormat:=xlExcel8
        NewWorkB = NewWb.Name
        

        
        J = 1
        K = 1
        'Date Col F
        DateCol = 6
        TDate = Format(Now, "mm/dd/yyyy")
        Todate = DateValue(TDate) + 1
        MaxRow = WS.UsedRange.Rows.Count
        WS.UsedRange.AutoFilter Field:=DateCol, Criteria1:=">=" & TDate, Operator:=xlAnd, Criteria2:="<" & Todate
        
        For I = 1 To MaxRow
            If WS.Range(I & ":" & I).EntireRow.Hidden = False Then
                
                If J = 1 Then
                    '---> Create the Header for the First Time
                    'Customer Identifier Currency    Amount  Merchant Reference
                    NewWS.Cells(J, "A") = "Customer Identifier"
                    NewWS.Cells(J, "B") = "Currency"
                    NewWS.Cells(J, "C") = "Amount"
                    NewWS.Cells(J, "D") = "Merchant Reference"
                    NewWS.Range(J & ":" & J).Font.Bold = True
                Else
                    '---> Copy Col B from Visa to Col A of New File
                    NewWS.Cells(J, "A") = WS.Cells(I, "B")
                    
                    '---> Copy Col E from Visa to Col C of New File
                    NewWS.Cells(J, "C") = Format(WS.Cells(I, "E"), "€#,###.00")
                    
                    '---> Put EUR to Col B of New File
                    NewWS.Cells(J, "B") = "EUR"
                    
                    '---> Insert 'smcurrentYearMonthDate#' Visa to Col D of New File
                    NewWS.Cells(J, "D") = "sm" & Format(Year(SDate), "0000") & Format(Month(SDate), "00") & Format(Day(SDate), "00") & J - 1
                End If
                J = J + 1
            End If
        Next I
        WS.ShowAllData
        WS.AutoFilterMode = False
       
        With NewWS.Columns("A:D")
           .EntireColumn.AutoFit
           .HorizontalAlignment = xlCenter
        End With
           
        Application.DisplayAlerts = False
        
        For Each WSS In NewWb.Worksheets
            If WSS.Name <> NewWS.Name Then WSS.Delete
        Next WSS
        
        
        NewWb.Save
        
        'Set NewWb = Nothing
        'Set NewWS = Nothing
        Application.DisplayAlerts = True
        
        'ws.Activate
        MsgBox ("Workbook: '" & NewWorkB & "' has been created successfully")
          
        
    End If
End If
End Sub


Function GetNewFolder(fFolder As String, Title As String)

fFolder = GFolderName(Title)

If fFolder <> "" And Dir(fFolder) <> "" Then
    GetNewFolder = fFolder
Else
    MsgBox ("No Folder has been selected or the Folder does not exist, therefore data cannot be Exported" _
        & " until valid Folder has been selected." & Chr(10) & Chr(10) _
        & "Please press on the command bar to choose a Folder.")
    GetNewFolder = "Browse"

    With Application
        .DisplayAlerts = True
        .EnableEvents = True
    End With
    
    Exit Function
End If
End Function

Open in new window


10) SAVE the workbook.
11) goto the worksheet and select sheet Main
12) select developper menu and make sure Design is clicked.
13) I suggest you open separately at this stage the file Main.xlsm just for you to make your life easier and get inspired on how I arranged for both command buttons that will need to create the second one. You will need to make room downward enough to fit in the command button and the label that is in top like in the sheet Main that I posted in the workbook main.xlsm
14) Once you have created the commandbutton (you can select the existing one and right click copy paste and same for the label then right click property and change their description to be as per the Main I send you.
15) Once this is done (I think you already have the button Generate Visa File if I am not mistaken as lost track of events if this was done before or now !!! I think it was done before and now we fixed the date on the sheet and the decimal and format euro ..) ok so now we need to fit in the code for sheet Main it will be a bit tricky here and you need to be careful
16) SAVE the workbook
17) doubleclick on the new button (Visa select folder button) and put this code:
===========
Private Sub CommandButton11_Click()
gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

End Sub
============
NOTE it should be commandbutton11 if it is not then I need to know as the whole logic need to be ammended. but in any case paste the code that is between Sub and end sub.
18) you need to do the same for the other button the WU button
============
Private Sub CommandButton3_Click()
gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"

End Sub
============
It should also be commandbutton3 if not then I need to know so we can ammend the code and also here paste the code that is between Sub and end sub.
19) SAVE the workbook.
20) Select to view 1 sub at a time in here and select worksheet Activate and delete the whole code there and paste the below code after any end sub

 
Private Sub Worksheet_Activate()
On Error GoTo ErrhandlerAct

If StartPGM Then
    FillCombo ComboBox1
    FillCombo ComboBox2
    
    gstFolderToMonitor = ComboBox1
    gstFolderToTransfer = ComboBox2
    
    If gstFolderToMonitor = "" Then
        MsgBox ("Please select a Folder to Monitor Emails")
    Else
        ComboBox1.Text = gstFolderToMonitor
    End If
    
    If gstFolderToTransfer = "" Then
        MsgBox ("Please select a Folder to Transfer Emails Imported")
    Else
        ComboBox2.Text = gstFolderToTransfer
    End If
    
    If ComboBox1 <> "" And ComboBox2 <> "" And gstFolderToMonitor <> "" And gstFolderToTransfer <> "" Then
        CommandButton1.Enabled = True
    Else
        CommandButton1.Enabled = False
    End If
    
    If gstFolderWesternUnion = vbNullString Then
    gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
    End If
    Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"
        
    If gstFolderVisaFile = vbNullString Then
    gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
    End If
    Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

    
    If gstGenerateWUName <> gstGenerateWUEmail Then
        MsgBox ("Please note that File : '" & gstGenerateWUName & "' has been created, however not Emailed." & Chr(10) & Chr(10) _
            & "You should proceed to select [Generate Email & Update 'WU-Staging-FBME'] button to Email the created file." & Chr(10) & Chr(10) _
            & "You may at any time, select [Generate WU File] to build a new file for Export")
    End If
    
    wsMain.Range("L" & CRow) = "Main Activate - gstFolderToMonitor: " & gstFolderToMonitor
    wsMain.Range("L" & CRow + 1) = "Main Activate - gstFolderToTransfer: " & gstFolderToTransfer
    wsMain.Range("L" & CRow + 2) = "Main Activate - gstFolderWesternUnion: " & gstFolderWesternUnion
    wsMain.Range("L" & CRow + 3) = "Main Activate - gstFolderVisaFile: " & gstFolderVisaFile
    CRow = CRow + 4
    StartPGM = False
End If

Exit Sub

ErrhandlerAct:
MsgBox (Error(Err))
Resume Next

End Sub

Open in new window


21) SAVE the workbook and Exit
22) Start and cross finguers to hv it work !!!

Let me know
gowflow
Avatar of JaseSt

ASKER

I'm not following this:

20) Select to view 1 sub at a time in here and select worksheet Activate and delete the whole code there and paste the below code after any end sub

Do you mean go to ThisWorkbook and delete:

Private Sub Workbook_Activate()

End Sub ?

And replace it with the code above?
NO
at 20 we are in the code of Sheet Main so there on the left dropdown in top you have worksheet you select it then make sure you are in the sub worksheet activate there you delete the code and paste the one I attached at that point.
gowflow
Avatar of JaseSt

ASKER

Sorry, this is being such a pain.

Following, I believe, exactly as you stated above, am getting errors. When I first reopen the Visa workbook I get this: User generated image
Clicking on Ok, get the following: User generated image User generated image
Avatar of JaseSt

ASKER

I had to go back to a version from Dec 20 that did not have the Generate Visa Button, so recreated. I made sure the button numbers were exactly as you had in your Main sheet.
Avatar of JaseSt

ASKER

Just to verify, the below code is what I have in Sheet Main
Private Sub Combobox1_Change()
gstFolderToMonitor = ComboBox1.Text
If ComboBox1 <> "" And ComboBox2 <> "" Then
    CommandButton1.Enabled = True
Else
    CommandButton1.Enabled = False
End If
wsMain.Range("L" & CRow) = "Combo1 Change - " & gstFolderToMonitor
CRow = CRow + 1

End Sub

Private Sub ComboBox2_Change()
gstFolderToTransfer = ComboBox2.Text

If ComboBox1 <> "" And ComboBox2 <> "" Then
    CommandButton1.Enabled = True
Else
    CommandButton1.Enabled = False
End If
wsMain.Range("L" & CRow) = "Combo2 Change - " & gstFolderToTransfer
CRow = CRow + 1
End Sub

Private Sub CommandButton1_Click()
'GetEmails
LocateEmails
End Sub



Private Sub CommandButton10_Click()
GenerateVisaFile
End Sub

Private Sub CommandButton11_Click()
gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

End Sub

Private Sub CommandButton2_Click()
ImportWesternUnion
End Sub

Private Sub CommandButton3_Click()
gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"

End Sub

Private Sub CommandButton4_Click()
WMFileCreate Sheets("WU-Staging-FBME")
End Sub

Private Sub CommandButton5_Click()
If gstGenerateWUName = "" Then
    MsgBox ("You should Run command [Generate WU File] first, as no file has been generated yet.")
Else
    If gstGenerateWUName = gstGenerateWUEmail Then
        MsgBox ("File : '" & gstGenerateWUEmail & "' has already been emailed. You should Run command [Generate WU File] to create a new file.")
    Else
        If gstGenerateWUName <> "" And gstGenerateWUEmail = "" Then
            WUEmailCreate Sheets("WU-Staging-FBME"), gstGenerateWUName
        End If
    End If
End If
End Sub
Private Sub Worksheet_Activate()
On Error GoTo ErrhandlerAct

If StartPGM Then
    FillCombo ComboBox1
    FillCombo ComboBox2
    
    gstFolderToMonitor = ComboBox1
    gstFolderToTransfer = ComboBox2
    
    If gstFolderToMonitor = "" Then
        MsgBox ("Please select a Folder to Monitor Emails")
    Else
        ComboBox1.Text = gstFolderToMonitor
    End If
    
    If gstFolderToTransfer = "" Then
        MsgBox ("Please select a Folder to Transfer Emails Imported")
    Else
        ComboBox2.Text = gstFolderToTransfer
    End If
    
    If ComboBox1 <> "" And ComboBox2 <> "" And gstFolderToMonitor <> "" And gstFolderToTransfer <> "" Then
        CommandButton1.Enabled = True
    Else
        CommandButton1.Enabled = False
    End If
    
    If gstFolderWesternUnion = vbNullString Then
    gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
    End If
    Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"
        
    If gstFolderVisaFile = vbNullString Then
    gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
    End If
    Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

    
    If gstGenerateWUName <> gstGenerateWUEmail Then
        MsgBox ("Please note that File : '" & gstGenerateWUName & "' has been created, however not Emailed." & Chr(10) & Chr(10) _
            & "You should proceed to select [Generate Email & Update 'WU-Staging-FBME'] button to Email the created file." & Chr(10) & Chr(10) _
            & "You may at any time, select [Generate WU File] to build a new file for Export")
    End If
    
    wsMain.Range("L" & CRow) = "Main Activate - gstFolderToMonitor: " & gstFolderToMonitor
    wsMain.Range("L" & CRow + 1) = "Main Activate - gstFolderToTransfer: " & gstFolderToTransfer
    wsMain.Range("L" & CRow + 2) = "Main Activate - gstFolderWesternUnion: " & gstFolderWesternUnion
    wsMain.Range("L" & CRow + 3) = "Main Activate - gstFolderVisaFile: " & gstFolderVisaFile
    CRow = CRow + 4
    StartPGM = False
End If

Exit Sub

ErrhandlerAct:
MsgBox (Error(Err))
Resume Next

End Sub

Private Sub CommandButton6_Click()
ImportWUConfirmedAmts
End Sub

Private Sub CommandButton7_Click()
Dim SDate As String
Do
    SDate = InputBox("Please Enter Start Date for beginning tracking WU Balance", "Start Date", "10/18/2011")
Loop Until IsDate(SDate)

UpdateWUBalance SDate
End Sub

Private Sub CommandButton8_Click()
LocateEmailsToTabsNew
End Sub

Private Sub CommandButton9_Click()
CrossCheckVisaAndDB
End Sub

Private Sub Label4_Click()

End Sub



Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

End Sub

Open in new window

sorry complete mess here. Can you post the sheet main pls
gowflow
Avatar of JaseSt

ASKER

Private Sub Combobox1_Change()
gstFolderToMonitor = ComboBox1.Text
If ComboBox1 <> "" And ComboBox2 <> "" Then
    CommandButton1.Enabled = True
Else
    CommandButton1.Enabled = False
End If
wsMain.Range("L" & CRow) = "Combo1 Change - " & gstFolderToMonitor
CRow = CRow + 1

End Sub

Private Sub ComboBox2_Change()
gstFolderToTransfer = ComboBox2.Text

If ComboBox1 <> "" And ComboBox2 <> "" Then
    CommandButton1.Enabled = True
Else
    CommandButton1.Enabled = False
End If
wsMain.Range("L" & CRow) = "Combo2 Change - " & gstFolderToTransfer
CRow = CRow + 1
End Sub

Private Sub CommandButton1_Click()
'GetEmails
LocateEmails
End Sub



Private Sub CommandButton10_Click()
GenerateVisaFile
End Sub

Private Sub CommandButton11_Click()
gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

End Sub

Private Sub CommandButton2_Click()
ImportWesternUnion
End Sub

Private Sub CommandButton3_Click()
gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"

End Sub

Private Sub CommandButton4_Click()
WMFileCreate Sheets("WU-Staging-FBME")
End Sub

Private Sub CommandButton5_Click()
If gstGenerateWUName = "" Then
    MsgBox ("You should Run command [Generate WU File] first, as no file has been generated yet.")
Else
    If gstGenerateWUName = gstGenerateWUEmail Then
        MsgBox ("File : '" & gstGenerateWUEmail & "' has already been emailed. You should Run command [Generate WU File] to create a new file.")
    Else
        If gstGenerateWUName <> "" And gstGenerateWUEmail = "" Then
            WUEmailCreate Sheets("WU-Staging-FBME"), gstGenerateWUName
        End If
    End If
End If
End Sub
Private Sub Worksheet_Activate()
On Error GoTo ErrhandlerAct

If StartPGM Then
    FillCombo ComboBox1
    FillCombo ComboBox2
    
    gstFolderToMonitor = ComboBox1
    gstFolderToTransfer = ComboBox2
    
    If gstFolderToMonitor = "" Then
        MsgBox ("Please select a Folder to Monitor Emails")
    Else
        ComboBox1.Text = gstFolderToMonitor
    End If
    
    If gstFolderToTransfer = "" Then
        MsgBox ("Please select a Folder to Transfer Emails Imported")
    Else
        ComboBox2.Text = gstFolderToTransfer
    End If
    
    If ComboBox1 <> "" And ComboBox2 <> "" And gstFolderToMonitor <> "" And gstFolderToTransfer <> "" Then
        CommandButton1.Enabled = True
    Else
        CommandButton1.Enabled = False
    End If
    
    If gstFolderWesternUnion = vbNullString Then
    gstFolderWesternUnion = GetNewFolder(gstFolderWesternUnion, "Import WU file")
    End If
    Sheets("Main").CommandButton3.Caption = "Target Export Folder for Western Union: <" & gstFolderWesternUnion & "> ... Activated"
        
    If gstFolderVisaFile = vbNullString Then
    gstFolderVisaFile = GetNewFolder(gstFolderVisaFile, "Import Visa file")
    End If
    Sheets("Main").CommandButton11.Caption = "Target Export Folder for Visa File: <" & gstFolderVisaFile & "> ... Activated"

    
    If gstGenerateWUName <> gstGenerateWUEmail Then
        MsgBox ("Please note that File : '" & gstGenerateWUName & "' has been created, however not Emailed." & Chr(10) & Chr(10) _
            & "You should proceed to select [Generate Email & Update 'WU-Staging-FBME'] button to Email the created file." & Chr(10) & Chr(10) _
            & "You may at any time, select [Generate WU File] to build a new file for Export")
    End If
    
    wsMain.Range("L" & CRow) = "Main Activate - gstFolderToMonitor: " & gstFolderToMonitor
    wsMain.Range("L" & CRow + 1) = "Main Activate - gstFolderToTransfer: " & gstFolderToTransfer
    wsMain.Range("L" & CRow + 2) = "Main Activate - gstFolderWesternUnion: " & gstFolderWesternUnion
    wsMain.Range("L" & CRow + 3) = "Main Activate - gstFolderVisaFile: " & gstFolderVisaFile
    CRow = CRow + 4
    StartPGM = False
End If

Exit Sub

ErrhandlerAct:
MsgBox (Error(Err))
Resume Next

End Sub

Private Sub CommandButton6_Click()
ImportWUConfirmedAmts
End Sub

Private Sub CommandButton7_Click()
Dim SDate As String
Do
    SDate = InputBox("Please Enter Start Date for beginning tracking WU Balance", "Start Date", "10/18/2011")
Loop Until IsDate(SDate)

UpdateWUBalance SDate
End Sub

Private Sub CommandButton8_Click()
LocateEmailsToTabsNew
End Sub

Private Sub CommandButton9_Click()
CrossCheckVisaAndDB
End Sub

Private Sub Label4_Click()

End Sub



Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

End Sub

Open in new window

I said post the sheet not the code !
open the workbook right click on main choose move or copy tick on create a copy open the top dropdown and choose book1 or new book press ok you will see book1 with Main in it save it on your drive and this is the workbook I want to see posted. !!!
gowflow
Avatar of JaseSt

ASKER

Here you go.  I get up around 5-6am. Not sure what time that is for you. I'm in Montana.
Book1.xlsm
well we hv a diffrence on time of 9 hours I am at +2 you are at -7 gMT that makes it 9 hours so when it is 6am at yours it is already 3pm at mine !!! :) this is why sometimes I stay with you till 3 am !!! :)

Will  look at your sheet and already from the code you posted I hv a feeling we hv changes we don't hv same version of main. let me look it up and will revert soon.
gowflow
NO I want the Main you have not the one I posted I want this one
gowflow
VisaError1.gif
Avatar of JaseSt

ASKER

here you go. Book3.xlsm
Sorry it is working perffectly with your sheet I tried all options !!!
You need to be careful when you imported my main sheet it had in the folders monitro and transfer the settings for gowflow you should change these once you run the macro for your settings and then save the file close it and start again then all would work fine.
gowflow
Avatar of JaseSt

ASKER

I'm sorry, I don't understand what you are saying. What should I do now?
if in your present workbook you have the sheet you just send me then run the workbook and make sure the monitor folder are slected from the dropdown and transfer folder selected from the dropdown and let me know
gowflow
Avatar of JaseSt

ASKER

But that's just the problem. I can't do that. Just going to the page causes errors. :ByRef argument mismatch, with 'Private Sub Worksheet_Activate()' highlighted in yellow. Clicking on the new drop down button causes the same error with 'Private Sub CommandButton11_Click()' highlighted in yellow.

Maybe I should just start over.
maybe but when you get the yellow you also hv something highlighted in blue what it is ? I need to know what function is causing the error
gowlfow
Avatar of JaseSt

ASKER

Excuse me. Had to take my kids to school.

When I first open the Main sheet I get this: User generated image
When  I click on the Visa location button, I get this: User generated image
When I click on the Western Union location button, I get this: User generated image
ok try this
goto vba view 1 sub at a time find Function GetFolderNew and delete it and paste the below code after any end sub and save workbook. close it restart it and try it
gowflow
Function GetNewFolder(ByVal fFolder As String, Title As String)

fFolder = GFolderName(Title)

If fFolder <> "" And Dir(fFolder) <> "" Then
    GetNewFolder = fFolder
Else
    MsgBox ("No Folder has been selected or the Folder does not exist, therefore data cannot be Exported" _
        & " until valid Folder has been selected." & Chr(10) & Chr(10) _
        & "Please press on the command bar to choose a Folder.")
    GetNewFolder = "Browse"

    With Application
        .DisplayAlerts = True
        .EnableEvents = True
    End With
    
    Exit Function
End If
End Function

Open in new window

Avatar of JaseSt

ASKER

Getting somewhere.

When opening I get Invalid procedure call or argument and higlights in yellow:
 wsMain.Range("L" & CRow) = "Workbook Open - Error: <" & Error(Err) & ">"

However, when closing debug code I can now select folder for both the Western Union and Visa file locations. Couldn't do that before.

But, clicking Import Emails into Tabs gives: Object Required, with this line highlighted in yellow:
wsMain.Range("L" & CRow) = "Locate Emails - Error: <" & Error(Err) & "> Item " & VItem

Clicking on Import WU Emails gives the attached error: User generated image
ASKER CERTIFIED SOLUTION
Avatar of Jacques Geday
Jacques Geday
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JaseSt

ASKER

Halleluiah!!! It worked - although I had to change the location of my database file, but no biggie.

However there is one caveat. On going over everything it seems to all work, except the Import Emails into Tabs button. When clicked it says it does its job but nothing gets imported. I even moved back to the inbox one it had successufully processed before, but no go this time.


On another try (which happened once) I got Object variable or With block variable not set, with this line highlighted in yellow:

wsMain.Range("L" & CRow) = "Locate Emails - Error: <" & Error(Err) & "> Item " & VItem
both transfer and Monitor folders were set prior to running this ? do this open the workbook delete what is written for both combo the monitor and the transfer location green and blue combobox on top in main.
Then select both locations even if you don't use for transfer still select a folder from the dropdown for both once selected then save the workbook and exit it.
restart and try it.
gowflow
Avatar of JaseSt

ASKER

Yes, both transfer and Monitor folders were set prior to running this.

Did what you asked, but although it identifies the emails to process with a pop up message:
"Email From: [xxxxx - xxxxx Person's Name] Not Imported" it does not import the data to the Wire-Staging-FBME sheet.
ok did you have some solution fixed by other experts and these sub were intputed in module1 ?? if yes then obviously I don't hv this code and you deleted it when I asked you to delete all the code in module1 so to remedy you simply go to your last workbook open it and open this one and look for any sub or finction that exist in module1 that is the workbook and that is not here and simply copy it to this module.

If it is not the case then try checking again maybe the mail you just put is simply not to be imported and you are simply getting paniqued and the macrro works fine check again
gowflow
Avatar of JaseSt

ASKER

The only other expert who has worked on this file had me create another module to drop his code in and it works fine.

Now, interestingly, when I click on Import Emails to Tabs, I get an error which once again:

Object variable or With block variable not set, with this line highlighted in yellow:

wsMain.Range("L" & CRow) = "Locate Emails - Error: <" & Error(Err) & "> Item " & VItem
ok I will look into it maybe I gave you an old version of the sub I had fixed let me check that but beside this all is fine ?
gowflow
once you get object variable you should close the workbook and try again
gowflow
Avatar of JaseSt

ASKER

Yes, I do close and retry and don't get error but also it no importing of data is done.
so what are we talking here the function Import Emails into Tab ? it is the only thing not working ? pls remind me the format of the email just in few words and what sheet it should update.
gowflow
Avatar of JaseSt

ASKER

Yes, that is what we are talking about. As far as I can tell, it is the only thing not working. It should update sheet Wire-Staging-FBME

The body of the email is like this:

Dear Client,
You have received a Payment.
From: 10xxxxxxxx - 4381xxxxxxxxx102 Joey Smith
Amount: EUR 3000.00
Please log in and check your EUR-account statement for more details.

(This is an automatic notification.)
Kind regards
Customer Support
well for sure it will not work you hv diffrent emails now with customer code did I adapt this ?? I don't think I hv dome that or else my mem is failing me !
I checked the emails I have and this is the sample I have
Dear Client,
You have received a Payment.
From: 4XXX 0XXX 0XXX XXXX JAMES HANS
Amount: EUR 980.50
Please log in and check your EUR-account statement for more details.

(This is an automatic notification.)
Kind regards
Customer Support

I covered the CC by X
object of this questio nwas the generate visa file to which you did not give me feedback. If the importtotab has a problem I think this should be addressed separately after this question is dealt with.
gowflow
Avatar of JaseSt

ASKER

No. Don't you remember that the format for these emails changed? You had to change the code so that it would now process emails that had the "10xxxxxxxx - " proceeding the card number. If you want me to submit it as a related question, sure, but it worked before this latest update to the code.

Let me know.
yes I remember and the file I hv here has the cust number in card number and you said you would sqithch it I rmeember. Don't know why its not working.
Then no need to post a question can you attach some emails of this type with credit card 5 and 4 to check pls put as many as you can from this new format and save as .msg and zip and attach
gowflow
Avatar of JaseSt

ASKER

will do. be back in an hour
Avatar of JaseSt

ASKER

Sorry, took me longer because I'm trying to find the history for this question. There was this:

https://www.experts-exchange.com/questions/27475716/related-to-Outlook-to-Spreadsheet-previous-question.html

But that didn't account for other emails to be imported to the Visa workbook like deposits and to the HMF Visa and Victor Group tabs. You should have this code already. VisaRegularPayment-Received.msg
well this is under Import Emails green button not Import Emails into Tabs
well i am lost now before I go further try importing these emails thru the Import emails
gowflow
Avatar of JaseSt

ASKER

Huh! Well that worked. I am so very sorry. Switching to your imported Main sheet, with its different colored buttons must have thrown my simple mind :/

Well, all seems to work fine now.

However... after feedback from the bank using the spreadsheet you creat I am told I can't use it as it has no macros. So.... I'll submit a related question if you can and are willing - so when clicking on the Generate Visa File button it will open up a previously used spreadsheet and populate it with the same data you did to the newly created spreadsheet. Let me know.

Once again, my apologies.
Avatar of JaseSt

ASKER

gowflow is not only an expert, he's a professional through and through.
tks and glad we got this sorted out. Pls go ahead with your next question but not sure I understood what you said:
so when clicking on the Generate Visa File button it will open up a previously used spreadsheet and populate it with the same data you did to the newly created spreadsheet.
???
You will need to tell me what you want in that question
gowflow