Continue running a Macro after Exiting a Macro that was inside the Macro

makaveli621

New Member
Joined
Apr 30, 2012
Messages
26
I created a userform with a combobox that populates picture files name and I also have an image box that displays a preview (say 200x200) of the picture that the user has selected from the combobox. I placed a macro on the image box that when the users clicks on it, another userform pops out but this one contains the full size picture (800x600).

The problem I have is that when I click on the image box to view the full size picture and then exit out (Close Out), the image box on the userform stops working, stops showing previews of the files you select from the combobox, it stays on the picture you have previewed.

How can you make the image box continue showing previews from the combobox?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
This is the code I have on the ComboBox (Named cbPicLocationList).

Private Sub cbPicLocationList_Click()
Dim fPath As String

fPath = "F:\Tiipping floor\WM Spreadsheet Photos\" & Sheets("HidFrm").Range("B2").Text & "\"

Image1.Picture = LoadPicture(fPath & frmChangePic.cbPicLocationList.Value)

End Sub

=================================

This is the macro I have on the Image Control (named Image1) that allows users to click on the image to make it bigger

Private Sub Image1_Click()
UserFormEnlargePic.Show
End Sub

==================================

Below is the code that runs the UserFormEnlargePic

Private Sub UserForm_Activate()
Dim fPath As String

fPath = "F:\Tiipping floor\WM Spreadsheet Photos\" & Sheets("HidFrm").Range("B2").Text & "\"

Image621.Picture = LoadPicture(fPath & frmChangePic.cbPicLocationList.Value)

End Sub
 
Upvote 0
Have you tried closing the 2nd userform when you reshow the first one?

Not sure exactly how you would do that as you've not posted the code that closes the 2nd userform and returns to the 1st userform.

Also, how and when are you populating the combobox on the 1st combobox?
 
Upvote 0
Im closing the 2nd Userform by clicking on the x button located on the top right corner of the userform.

And as far as populating the combobox the code is below:

Code:
Private Sub txtEnterSubFolder_AfterUpdate()


Dim objFSO As Object
    Dim objFolder As Object
    Dim objFile As Object
    Dim ws As Worksheet
    
    
    Sheets("HidFrm").Select
    Columns("A:A").Select
    Selection.ClearContents
    Selection.ClearComments
    
    
    Sheets("HidFrm").Range("A1").Select
    ActiveCell.FormulaR1C1 = "PATH FOLDER"
    
    Sheets("HidFrm").Range("A2").Select
    ActiveCell.FormulaR1C1 = "DATE"
    Sheets("HidFrm").Range("A3").Select
    ActiveCell.FormulaR1C1 = "WIDTH"
    Sheets("HidFrm").Range("A4").Select
    ActiveCell.FormulaR1C1 = "HEIGHT"
    Sheets("HidFrm").Range("A5").Select
    ActiveCell.FormulaR1C1 = "PicLocation"
    
    txtEnterSubFolder = Sheets("HidFrm").Range("C2").Text
         
        
   Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set ws = Sheets("HidFrm")
     
      'Get the folder object associated with the directory
     Set objFolder = objFSO.GetFolder("F:\Tiipping floor\WM Spreadsheet Photos\" & Sheets("HidFrm").Range("B2").Text)
       ws.Range("A6").Value = "The files found in " & objFolder.Name & " are: "
    
     
     'Loop through the Files collection
     
     
    For Each objFile In objFolder.Files
        ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
    Next
                                     
     'Clean up!
    Set objFolder = Nothing
    Set objFile = Nothing
    Set objFSO = Nothing
        

Sheets("DATABASE").Activate

End Sub
 
Upvote 0
[Highlight]sorry, below is a clear explanation.[/Highlight]

Im closing the 2nd Userform by clicking on the x button located on the top right corner of the userform.

And as far as populating the combobox, I have sheet called HidFrm and in column A is where I have all the names of the pic files and I did a dynamic name range using the offset formula and named it "PicLocation" which starts in row 7 (A7). And then On the combobox properties, RowSource I typed in "PicLocation", the dynamic name range and that's how it populates the combobox.
Code:
=OFFSET(HidFrm!$A$7,,,COUNTA(HidFrm!$A$7:$A$510))


But on top of the combobox I have textbox form that you type in the date of the subfolder in which all the pictures are and it populates it in the dynamic name range cells so the combobox can use.

the code is below:

Code:
Private Sub txtEnterSubFolder_AfterUpdate()

Dim objFSO As Object
    Dim objFolder As Object
    Dim objFile As Object
    Dim ws As Worksheet
    
    Sheets("HidFrm").Select
    Columns("A:A").Select
    Selection.ClearContents
    Selection.ClearComments
    
    Sheets("HidFrm").Range("A1").Select
    ActiveCell.FormulaR1C1 = "PATH FOLDER"
    
    Sheets("HidFrm").Range("A2").Select
    ActiveCell.FormulaR1C1 = "DATE"
    Sheets("HidFrm").Range("A3").Select
    ActiveCell.FormulaR1C1 = "WIDTH"
    Sheets("HidFrm").Range("A4").Select
    ActiveCell.FormulaR1C1 = "HEIGHT"
    Sheets("HidFrm").Range("A5").Select
    ActiveCell.FormulaR1C1 = "PicLocation"
    
    txtEnterSubFolder = Sheets("HidFrm").Range("C2").Text
         
        
   Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set ws = Sheets("HidFrm")
     
      'Get the folder object associated with the directory
     Set objFolder = objFSO.GetFolder("F:\Tiipping floor\WM Spreadsheet Photos\" & Sheets("HidFrm").Range("B2").Text)
       ws.Range("A6").Value = "The files found in " & objFolder.Name & " are: "  
     
     'Loop through the Files collection
          
    For Each objFile In objFolder.Files
        ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
    Next
                                     
     'Clean up!
    Set objFolder = Nothing
    Set objFile = Nothing
    Set objFSO = Nothing       

Sheets("DATABASE").Activate

End Sub
 
Upvote 0

Forum statistics

Threads
1,203,655
Messages
6,056,571
Members
444,877
Latest member
kat517

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