Posts by archleo

    Re: Getting Events of Dynamically Added Form Controls


    Hi cytop

    I'm still unable to solve my issue, I've worked hard, searched a lot, have tried may be 100 code solutions, but it seems that no one works or I'm a real idiot and cannot be able to see the solution. Can you show me a way out and help me? It is highly highly appreciated my friend.


    Regards,


    Levent

    Re: Getting Events of Dynamically Added Form Controls


    cytop,


    Normally I would read the value of a checkbox and assign a value to a variable like this:


    I do apologize for my dumass question but I'm not quite understood how can I get this from this situation.

    Re: Getting Events of Dynamically Added Form Controls


    Quote from cytop;749295

    You forgot

    Code
    Set chkBoxColl = New Collection


    Or just declare it ' ... As New...' but people generally don't like that.


    cytop you are an angel my friend...
    it worked like a charm...
    However, I think I'm missing something here, because it only reads the last added control name with the cBox_Click() event. However, I have to be able to read all of them, because I have to assign a public variable to all in order to read the checked/unchecked status of them. How can I manage this?

    Hi valuable Members,


    I'm dynamically adding (via VBA) a number of CheckBox controls to my UserForm, which reads the number of controls to be added from a variable. I have searched some forums on how to get the values and/or events of these checkboxes and finally found an answer that I have to go thru a collection of events. I have created a class module, and structured my UserForm_Initialize event, however when I run the UF, it fires an error:

    Quote


    Run-time error '91':


    Object variable or With block variable not set


    Here are my codes and I appreciate your help. Best regards to you all.
    Class Module - clsBoxEvent


    Code
    Option Explicit
    
    
    Public WithEvents cBox As MSForms.CheckBox
    
    
    Private Sub cBox_Click()
        MsgBox cBox.Name
    End Sub


    UserForm Module

    Re: Looking for a VBA code to protect deletion of rows


    It is a 3 simple step where you do not need a macro:


    1.) Select your range of cells you wish to allow to be changed and choose FORMAT CELLS from the context menu, click the PROTECT tab. Uncheck the "locked" box. and click OK.


    2.) Go to Tools > Protect > Protect Sheet


    3.) Check everything you want to allow... uncheck things you wish not to allow


    Do not forget to enter a memorable password (2 times...)


    Voila...

    Re: Code to auto filter data base on a list of file and generate different reports


    Hi David,


    Regarding your question; simplest thing to do would be to append each filtering criteria to a dynamic variable and then according to your selection of Country and Business type, apply the filtering according to that criteria. I've understood (hopefully) your problem however it is not so possible to design or re-structure a code without seeing your macro. Please do find below a code snippet that I currently use on one of my files:

    Re: Code to send emails to a list of recipients (both to and cc) from excel


    Hi David


    Please download the workbook from below link for your question. Hope that it helps.
    https://www.dropbox.com/s/v12naqka5e2atyf/MailingSampleWB.xlsm?dl=0


    For others to see the solution:
    Workbook contains a Module and a UserForm


    Module Level Coding:


    UserForm Level Coding:



    Regards,


    Levent


    OPs: Sorry for providing a dropbox link, however I couldn't manage to attach the file here.

    Re: Code to send emails to a list of recipients (both to and cc) from excel



    Good morning David,


    Sorry for replying you late, but I've had a problematic net connection thru my ISP yesterday night.
    I have some questions regarding your solution:
    1.) Is your business type fixed with respect to countries? I mean i.e. is F&B only for UK and Trading only for US? Or does every country own every business type?
    2.) Are there only one email address in TO and CC? Will there be more people (esp. in CC)?


    Best regards,


    Levent

    Re: Code to send emails to a list of recipients (both to and cc) from excel



    Hi ducdohoang,


    I'm on the way to home and I will respond to your thread in a couple of hours. FYI, E1:Z1 Range is reserved for attachments as I don't have any idea how many reports you want to send regarding each 'Business'. I'll try to modify the code as per your needs tonight and send it.


    Best regards,

    Hi valuable forum members,


    Firstly I want to explain the situation (with simple and short wordings hopefully :smile: )


    1. I've prepared a Document Management Log in Excel with full of macros, procedures etc. (the problem that you've solved was a part of that system by the way)
    2. All the files of that system is partly and sometimes fully linked together.
    3. All the system files lies in a network drive (L:\)
    4. All the system files lies in their respective folders (i.e. MP02, MP03 etc.)
    5. As I don't want any user copy or move any system file outside their drive & folder, I've constructed a simple code under Workbook_Open() Event, so that it cannot be operated, like below:

    Code
    Private Sub Workbook_Open()      If InStr(LCase(ThisWorkbook.FullName), "l:\esso") = 0 Then        MsgBox "ATTENTION!! THE FILE YOU WANTED TO OPEN IS PART OF A PROJECT AND CANNOT BE EXECUTED OUTSIDE ITS WORKING ENVIRONMENT. THIS FILE WILL BE CLOSED NOW...", vbExclamation, "UNAUTHORIZED USE DETECTED..."         ThisWorkbook.Close False     Else. . .      End IfEnd Sub


    6. For this system, I have a major file (2D_EMAAR_DMS.xlsm) and every single log file under this system have to be opened thru this (let's call it) 'Control Center' because there are macros run when selected from here to collect data from other system files.


    And here's the tricky question:
    Log files of the system can be opened with just a simple double click inside their folder. And as the file is not opened via 'Control Center', some macros unfortunately fail to operate and users do not pay attention ending with messing up my log files.


    QUESTION: How can I force users to open the file via 'Control Center' and force a Workbook.Close False event if the files have been tried to open solely from inside their folders?


    Thank you everyone for their contribution and help. It is highly appreciated on my side.


    Best regards,

    Re: Code to send emails to a list of recipients (both to and cc) from excel


    You can try this:
    This code also attaches the Excel report (or any other file you've specified) to your mail
    Assuming that you're using outlook and full path+file name of the report lies in Range("E5:Z5")
    Assuming that you're sending one (or more than one) report at the same e-mail
    Assuming that WorkSheet name is "MAILING" (you can change this according to your needs)


    I've little bit changed your table, but you can edit the table and code accordingly as per your needs


    [TABLE="class: grid, width: 1000, align: left"]

    [tr]


    [td][/td]


    [td]

    A

    [/td]


    [td]

    B

    [/td]


    [td]

    C

    [/td]


    [td]

    D

    [/td]


    [td]

    E

    [/td]


    [td]

    .

    [/td]


    [td]

    .

    [/td]


    [td]

    AA

    [/td]


    [td]

    AB

    [/td]


    [/tr]


    [tr]


    [td]

    1

    [/td]


    [td]

    UK

    [/td]


    [td]

    F&B

    [/td]


    [td]

    [email protected]

    [/td]


    [td]

    [email protected]

    [/td]


    [td]

    C:\Downloads\UK_Report.pdf

    [/td]


    [td][/td]


    [td][/td]


    [td]

    Report Date

    [/td]


    [td]

    05-05-2015

    [/td]


    [/tr]


    [tr]


    [td]

    2

    [/td]


    [td]

    US

    [/td]


    [td]

    Trading

    [/td]


    [td]

    [email protected]

    [/td]


    [td]

    [email protected]

    [/td]


    [td]

    C:\Downloads\US_Report.pdf

    [/td]


    [td][/td]


    [td][/td]


    [td]

    Next Report Date

    [/td]


    [td]

    08-08-2015

    [/td]


    [/tr]


    [/TABLE]







    Re: How To Refresh UserForm ListBox


    Hi cytop,


    I don't know how to thank you my friend. Everything is just like I wanted know the code works flawlessly...
    Thank you so much for your help and efforts...
    Problem solved, case closed...

    Re: How To Refresh UserForm ListBox


    Quote from cytop;747162

    OK - have nothing to do this afternoon. I'll edit your userform and post back later...


    God bless you cytop...Thank you so much for your help
    And provided one day you think to take a trip or vacation to Istanbul, Turkey, I'll be honoured to guest you.
    Regards,

    Re: How To Refresh UserForm ListBox


    Quote from cytop;747149

    Unfortunately, I think language barriers are a little high here - and English is my second language too :)


    Hi cytop,


    It is very well understood now that both your English and understanding are better than me pal :) :)


    What I want is exactly what you have written in 3 simple lines :) :) Shame on me that I just keep telling them with 3 full+full paragraphs :duh:


    1.) The files are named like 150526_MP02_Submittal_Log.xlsm. ListBox.Column1 shall be filled with the date as specified in the filename

    2.)
    ListBox.Column2 will contain the remainder of the file name with _'s replaced by spaces.


    3.) The user then double clicks an item, the full filename is build up and .......


    I also attach my files latest update FYI...forum.ozgrid.com/index.php?attachment/65389/


    You are a great guy and I appreciate your efforts. Thank you so much.

    Re: How To Refresh UserForm ListBox


    Quote from cytop;747086

    I'm sorry, maybe I'm having a bad day but I don;t understand what you mean by "...sort the listbox in a way that date matches the FName"


    I'm also sorry provided I couldn't express my issue well as for a couple of hours I see everything like sub, private sub, dim, private declare etc. :) :)
    What I've try to meant was: (please do apologize my dumb ass explaining style)
    1. My filename format in relevant folders are: yymmdd_PackageNr_Submittal_Log.xlsm (i.e. 150527_MP02_Submittal_Log.xlsm)
    2. File filename is read, put it in a listbox (lbFileList) row and the name is divided into 2 columns: Date & Filename (I have little bit changed your code like below)


    3. When the user chooses a backup file and double click, filename can be read appropriately

    Code
    MsgBox fileList(lbFileList.ListIndex + 2)


    No problem till here...
    But I want lbFileList listbox to be sorted in descending order (both columns), but "...sort the listbox in a way that date matches the FName" meaning:
    (selected item; theoretically) listbox column0 value ("27-05-15") + listbox column1 value ("MP02 Submittal Log") should point out "
    150527_MP02_Submittal_Log.xlsm"
    What the problem might be here is; there are some files where (manually given during saveas) "yymmdd" part of the filename might not match with the FileDateTime function, because there we read the actual saved date&time of the file. I mean; today (27/05/2015) I save the file but the log belongs to yesterday's data, so I saveas the file 150526_MP02_Submittal_Log.xlsm.


    To overcome this problem, I had tried to get the "date" values with below coding:

    Code
    Format(CDate(Mid(fName, 5, 2) & "/" & Mid(fName, 3, 2) & "/" & Mid(fName, 1, 2)), "dd-mm-yy")


    Sorry for too long explanation for a simple question, but I just wanted to reflect my idea very clearly.


    Thnx for your efforts pal...

    Re: How To Refresh UserForm ListBox


    Quote from cytop;747071


    Hi cytop,


    In fact this was the thread influenced me for sorting the listbox items (see my code above).
    My backup files are named with a format like "yymmdd_PackageNr_Submittal_Log.xlsm". As I didn't know how to stripe the file date (thnx to show me that on your code with FileDateTime(fPath & fName) I have tried to do that with CDate function by slicing the fName with Mid function putting the value to the first column of the Listbox. After that I've striped the year part from the fName and put the value to the second column with replacing "underscore" char's with spaces for a better look&feel. I was trying to do this splitting under the SortListBox procedure. That's what I have done bur couldn't managed so far :)


    Simply, I want to get the file list from the relevant folder (that's done), put them on a listbox with Date & FName columns (that's done too), sort the listbox in a way that date matches the FName (that's missing) and let the user open the backup log with double click the filename (that's easy if I can properly read the fPath and fName)

    Re: How To Refresh UserForm ListBox


    Thank you very much cytop...Now it works just like I wanted.
    Could you please also check the procedure SortListBox where I've tried to sort the items in lbFileList listbox?


    when I ran this code, I'm getting "Subscript Out of Range" error and the debugger points out this line:

    Code
    oLb.List(i, 0) = CDate(Mid(vItems(i, 0), 5, 2) & "/" & Mid(vItems(i, 0), 3, 2) & "/" & Mid(vItems(i, 0), 1, 2))

    Re: How To Refresh UserForm ListBox


    Quote from cytop;747048

    I don't understand


    There is no line in your code to clear the listbox... so everything just gets added in again. Look at DisplayFoldersInListBox, you'll see a Listbox.CLear statement, for example.


    Hi cytop,


    ListBox.clear statement at DisplayFoldersInListBox procedure only clears the lbFolderList listbox. As I have tried to explain above, I want lbFileList listbox to be cleared when user clicks/double clicks a "foldername" item in lbFolderList listbox. But though I have tried to put a statement like:

    Code
    ufBackupList.lbFileList.Clear


    in every possible place in the code, lbFileList is not cleared and filenames of selected folder always added to the end of the previous list.
    I have thought that the problem is within the dynamic array where I collect the filenames. From the code below:

    Code
    While fName <> "" 
             'add fName to the list
            If InStr(fName, "Submittal") > 0 Then 
                k = k + 1 
                Redim Preserve fileList(1 To k) 
                fileList(k) = fName 
            End If 
             'get next filename
            fName = Dir() 
        Wend


    I've understood that re-dimesioning an array with the "preserve" option, means to enlarge the array, preserving the data it previously have. I've tried to reset the array or empty the array in the very beginning of the procedure, but I couldn't manage it. Erasing the array, when the procedure called upon user click/double click a foldername item, results in empty list of items first followed by the new list of the foldername choosen.

    Re: How To Refresh UserForm ListBox


    Quote from cytop;747042

    You don't actually Clear the Listbox first...


    So sorry for the missing code...Here it is, but it does not clear the listbox...I've tried the piece of clearing line every possible place in my code