Posts by John_w

    Here is a new UIAutomation function, UIAutomation_Click_IE_Tab_By_URL, which activates the tab with the specified LocationURL. It finds the required tab by activating each tab in turn and extracting the URL from the IE address bar and comparing it to the required URL - which can contain wildcards, since the Like operator is used - until the required tab is activated.


    Here is the complete code, including a test routine and a function which loops through all IE windows and tabs until the required LocationURL is found.


    The error occurs at the yellow highlighted line because the IEtab object is Nothing. And IEtab is Nothing because there is no tab (a TabItemControl) with the name of your URL. The tab name of each tab in IE's UIAutomation elements is the LocationName, not the LocationURL.


    Here is a detailed description of how the code works:


    The main function, Find_and_Activate_IE_Tab, looks for the required tab by its LocationName or LocationURL. If found, it calls UIAutomation_Click_IE_Tab with the found LocationName and looks for the IE UI element with the specified tab name (a TabItemControl) and clicks (activates) that tab.


    The 2nd argument to UIAutomation_Click_IE_Tab must be the LocationName of the tab to be activated, not the LocationURL. The reason is that, amongst all IE's UIAutomation elements, the UI element containing the LocationURL is that of the already active tab in IE's address bar - it is a UI element with the class name "AddressDisplay Control". Although the URL of a tab is displayed when you hover over that tab, I have not seen this URL anywhere in IE's UIAutomation elements, so I don't think the code could be changed to look for the URL.

    You have to call Find_and_Activate_IE_Tab, which looks for the tab by its (partial) LocationURL or LocationName by looping through Shell.Windows. If found, it then calls UIAutomation_Click_IE_Tab to activate the tab. Find_and_Activate_IE_Tab uses the Like operator to look for the matching LocationURL or LocationName string, allowing wildcards in the TitleOrURL argument.


    This works for me:

    Try this macro:

    Payment received, thank you.


    Here is the macro, which includes code to reuse an existing IE window, so it doesn't open a new IE browser every time it's run.


    Try this:

    Payment received, thanks.


    I've just realised that 'new destination folder' in your OP might mean that the destination folder doesn't exist. Simply add this line below the ... Set FSO = ... line:


    Code
    1. If Not FSO.FolderExists(destinationFolderPath) Then FSO.CreateFolder destinationFolderPath

    and it will create the last folder in the destination folder path, if it doesn't already exist.


    Let me know if you require any other changes after testing.

    The trouble with referencing multiple elements in one line, as your For Each line does, is that you can't tell which part is failing. (The error is probably caused by getElementbyClassName - it should be getElementsByClassName.)


    Try this for the first four items - the others should be similar. Add a reference to MS HTML Object Library.


    It sounds like you could use the same class. But if my guess (you don't say exactly) that the idea with


    Code
    1. If tbxCustom1.Name = "txtbx2" Then
    2. KeyAscii = 0
    3. End If


    Is to prevent the user typing in or changing the txtbx2 field, why don't you set txtbx2 to read only at run-time by setting its Locked property to True:


    Code
    1. With newTextbox
    2. .Name = "txtbx" & i
    3. .Top = y + 20
    4. .Height = 18
    5. .Left = x
    6. .Width = 120
    7. .Font.Size = "10"
    8. .Font.Name = "Calibri"
    9. If .Name = "txtbx2" Then .Locked = True
    10. End With

    But without knowing what you are trying to do I can only guess.

    See if this macro does steps 1 to 4, as required. Rather than opening each selected .csv file, it uses a text query to import the data into the macro workbook. The first .csv file import starts at row 1, to include column headings, and subsequent files start at row 2 to omit them. I put comments in the code to help you to understand it.


    You don't seem to have copied the code correctly. In clsObjHandler you need:


    [VBA]Public Property Set Control(tbxNew As MSForms.TextBox)
    Set tbxCustom1 = tbxNew
    End Property
    [/VBA]And in the For Each loop (whose innards you could incorporate into the For i loop, rather than separate loops) change:


    [VBA]Set clsObject.tbxCustomEvent = ctlLoop
    [/VBA]to:


    [VBA]Set clsObject.Control = ctlLoop[/VBA]Then checking the textbox name inside the Keypress event should be:
    [VBA]If tbxCustom1.Name = "txtbx2" Then[/VBA]Also, you could declare colTbxs outside the procedures so you can clear it in the UserForm_Terminate event, as shown in the linked code.