Hi guys, it totally slipped my mind to come back here and post what i had done for this.
ok, so i made progess on this. my current situation is this.
*i have a userform in excel.
*when it opens i have 3 (i have about 20 but to explain this, we will say 3 because it will make the code i paste here alot smaller) text boxes with a button next to each one.
*there is another button at the bottom of the userform called 'open title block template' which opens an autocad drawing for me
*i then double click on a block which contains attributes in the cad drawing and it opens up a window called 'enhanced attribute editor'
*now i go back to the excel user form where the 3 buttons that are next to 3 text boxes are
*each button when clicked copies the text located in the textbox it is next to onto the clipboard, sets focus to the 'enhanced attribute editor' window, pastes the contents of the clipboard using the send key paste, then goes down to the next attribute using the send key enter.
*afetr clicking on the first button, i then click on the second, third etc and i am copying each textbox text into each attribute in autocad.
here is the code for the above.
Code:
Private Sub CommandButton14_Click()
Dim objData As DataObject
Dim strClipBoard As String
Set objData = New DataObject
'Clears the clipboard
objData.SetText ""
objData.PutInClipboard
'Puts the text from an textBox into the clipboard
strClipBoard = Me.TextBox1.Value
objData.SetText strClipBoard
objData.PutInClipboard
'Gets the text on the clipboard into a string variable
objData.GetFromClipboard
strClipBoard = ""
strClipBoard = objData.GetText
'Focus on autocad window
AppActivate ("Enhanced Attribute Editor")
'Paste command
Application.SendKeys ("^v") 'Excel's method
'Enter command and move down to next textbox in cad window
Application.SendKeys ("~") 'Excel's method
End Sub
Private Sub CommandButton15_Click()
Dim objData As DataObject
Dim strClipBoard As String
Set objData = New DataObject
'Clears the clipboard
objData.SetText ""
objData.PutInClipboard
'Puts the text from an textBox into the clipboard
strClipBoard = Me.TextBox2.Value
objData.SetText strClipBoard
objData.PutInClipboard
'Gets the text on the clipboard into a string variable
objData.GetFromClipboard
strClipBoard = ""
strClipBoard = objData.GetText
'Focus on autocad window
AppActivate ("Enhanced Attribute Editor")
'Paste command
Application.SendKeys ("^v") 'Excel's method
'Enter command
Application.SendKeys ("~") 'Excel's method
TextBox24.Text = Label3
End Sub
Private Sub CommandButton16_Click()
Dim objData As DataObject
Dim strClipBoard As String
Set objData = New DataObject
'Clears the clipboard
objData.SetText ""
objData.PutInClipboard
'Puts the text from an textBox into the clipboard
strClipBoard = Me.TextBox3.Value
objData.SetText strClipBoard
objData.PutInClipboard
'Gets the text on the clipboard into a string variable
objData.GetFromClipboard
strClipBoard = ""
strClipBoard = objData.GetText
'Focus on autocad window
AppActivate ("Enhanced Attribute Editor")
'Paste command
Application.SendKeys ("^v") 'Excel's method
'Enter command
Application.SendKeys ("~") 'Excel's method
TextBox24.Text = Label4
End Sub
so i have been doing this for all my new drawings over the last few months which is fine but have now decided that i want to do it in one big hit. i actually looked at this soon after applying the abive code but i just couldnt get around the problem and ended up giving up.
but now i want to try and get it working again. so the problem was and still is that it all works and everything is dany, but tbh, i dont want to click the 20+ buttons just to copy the contents over. i want to be able to hit one button and it runs the command of all button clicks. so i came up with this.
Code:
Private Sub CommandButton14_Click()
Dim objData As DataObject
Dim strClipBoard As String
Set objData = New DataObject
'Clears the clipboard
objData.SetText ""
objData.PutInClipboard
'Puts the text from an textBox into the clipboard
strClipBoard = Me.TextBox1.Value
objData.SetText strClipBoard
objData.PutInClipboard
'Gets the text on the clipboard into a string variable
objData.GetFromClipboard
strClipBoard = ""
strClipBoard = objData.GetText
'Focus on autocad window
AppActivate ("Enhanced Attribute Editor")
'Paste command
Application.SendKeys ("^v") 'Excel's method
'Enter command and move down to next textbox in cad window
Application.SendKeys ("~") 'Excel's method
Set objData = New DataObject
'Clears the clipboard
objData.SetText ""
objData.PutInClipboard
'Puts the text from an textBox into the clipboard
strClipBoard = Me.TextBox2.Value
objData.SetText strClipBoard
objData.PutInClipboard
'Gets the text on the clipboard into a string variable
objData.GetFromClipboard
strClipBoard = ""
strClipBoard = objData.GetText
'Focus on autocad window
AppActivate ("Enhanced Attribute Editor")
'Paste command
Application.SendKeys ("^v") 'Excel's method
'Enter command and move down to next textbox in cad window
Application.SendKeys ("~") 'Excel's method
Set objData = New DataObject
'Clears the clipboard
objData.SetText ""
objData.PutInClipboard
'Puts the text from an textBox into the clipboard
strClipBoard = Me.TextBox3.Value
objData.SetText strClipBoard
objData.PutInClipboard
'Gets the text on the clipboard into a string variable
objData.GetFromClipboard
strClipBoard = ""
strClipBoard = objData.GetText
'Focus on autocad window
AppActivate ("Enhanced Attribute Editor")
'Paste command
Application.SendKeys ("^v") 'Excel's method
'Enter command and move down to next textbox in cad window
Application.SendKeys ("~") 'Excel's method
End Sub
now this works as in it goes through all 3 lots of code in one click but problem is it pastes the text from the third textbox into all three attributes in autocad as opposed to the first textbox text being pasted into the first attribute, the second in the second attribute and the third in the third. it always seems to paste the last textbox text into all attributes.
does anyone know what the problem is?
why would it work when i click each button, but when i run it in one routine, why doesnt it? i though it might be the fact that in the one routine it doesnt have the end sub command after each copy and paste. i then tried things like plication.CutCopyMode = False which didnt seem to help.
thankyou
epd
just a reminder that this is also posted here
http://www.vbaexpress.com/forum/showthread.php?p=271707#post271707