OLEObjects.Add method closes active UserForm

rajjindu

New Member
Joined
Jun 9, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have a UserForm that adds an Image Control to the sheet5, but when the line of code that generates the Image Control runs it adds to the sheet and focus retains in the sheet and the current UserForm4 is forcibly closed.
private sub upload_click
Sheet5.OLEObjects.Add Filename:=Dir(fd.SelectedItems(1)), Link:=True, _
DisplayAsIcon:=True, IconFileName:=Dir(fd.SelectedItems(1)), _
IconIndex:=0, IconLabel:=Dir(fd.SelectedItems(1)), Left:=Sheet5.Cells(cloC.Row, 7).Left, Top:=Sheet5.Cells(cloC.Row, 7).Top, Width:=Sheet5.Cells(cloC.Row, 7).Width, Height:=Sheet5.Cells(cloC.Row, 7).Height

me.show vbmodeless or userform4.show vbmodeless
textbox3.setfocs //EXECUTES THIS LINE BUT GOES TO SHEET5 AND CLOSES THIS USERFORM FORCIBILY \\not working
end sub//STOPS HERE
....... i HAVE CODE
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi. So I looked at your code, and this line jumped out at me:
VBA Code:
me.show vbmodeless or userform4.show vbmodeless
What does the code actually say and where is the code located?
 
Upvote 0
Thanks for your reply. I tried both. Still I was getting error. So I changed my logic.
 
Upvote 0
Ok, well I think someone else may have to assist you because I need more information. You haven't answered my questions, and I don't want to spend any time guessing what the source code actually says. Hope you manage to solve it.
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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