Can you advise on this code please

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,251
Office Version
  1. 2007
Platform
  1. Windows
Code in use is as shown.

The code below does this.
I copy a bar code image from the internet.
I then click on the command button called BAR CODE 1 which is the code shown below & i now see the bar code has been pasted in the cells A8:B10
This works fine apart from when i press the command button i actually see the bar code from say the clipboard appear in cell Y1 then its pasted into the cell A8:B10

I dont see anything in the code that specifies why it appears in Y1 but can we make it appear in a cell off the viewing page say cell AA1



Rich (BB code):
Private Sub BarCode1_Click()
  Dim objPic As Picture
  
  ActiveSheet.Paste
  Set objPic = Selection
  With ActiveSheet.Range("A8:B10")
    If objPic.Width > .Width Then
      objPic.Width = .Width
      objPic.Left = .Left
    Else
      objPic.Left = .Left + (.Width - objPic.Width) / 2
    End If
    If objPic.Height > .Height Then
      objPic.Height = .Height
      objPic.Top = .Top
    Else
      objPic.Top = .Top + (.Height - objPic.Height) / 2
    End If
  End With
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
do you have any worksheetchange events that could be triggered, as your paste will be changing the sheet it should go off and do them

or you could try application.enableevents = false above activesheet.paste, just set it to true by the end of the code
 
Upvote 0
There is no change code.
I also tried the enableevents but you can still see the image thats providing i did it correct


Rich (BB code):
Private Sub BarCode1_Click()
  Dim objPic As Picture
  Application.EnableEvents = False
  ActiveSheet.Paste
  Set objPic = Selection
  With ActiveSheet.Range("A8:B10")
    If objPic.Width > .Width Then
      objPic.Width = .Width
      objPic.Left = .Left
    Else
      objPic.Left = .Left + (.Width - objPic.Width) / 2
    End If
    If objPic.Height > .Height Then
      objPic.Height = .Height
      objPic.Top = .Top
    Else
      objPic.Top = .Top + (.Height - objPic.Height) / 2
    End If
  End With
  Application.EnableEvents = True
End Sub
 
Upvote 0
you've done what is suggested, not sure what else is going on
 
Upvote 0
I feel like I must be missing something - isn't the reason because you haven't actually specified to where you want the clipboard pasted? ActiveSheet.Paste will just paste the contents of clipboard to wherever. You can specify where you want it pasted by selecting the cell - so if you want AA1, then put Range("AA1").Select before the line pasting it.
 
Upvote 0
I feel like I must be missing something - isn't the reason because you haven't actually specified to where you want the clipboard pasted? ActiveSheet.Paste will just paste the contents of clipboard to wherever. You can specify where you want it pasted by selecting the cell - so if you want AA1, then put Range("AA1").Select before the line pasting it.


You are correct.

After adding the code you mention for AA1 i am now off the page BUT by adding another line of code the same but with the cell B8 it brings it back.
So withing a split second all is done correctly.


Thanks for the help
 
Upvote 0

Forum statistics

Threads
1,215,749
Messages
6,126,661
Members
449,326
Latest member
asp123

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