Application communicating with Excel

  • Thread starter Thread starter Dan Tabla
  • Start date Start date
D

Dan Tabla

Hi all,

Please give me any suggestion regarding how to send to Excel, 5 strings that
I'm getting manualy by selecting/copy from another application.
I tryed my best and searched internet but I couldn't solve it.
Clipboard looks helpful but.. http://www.cpearson.com/excel/Clipboard.aspx

For example:

For i=1 to 5
ActiveSheet.Cells(1,i)=Selection/copy(i)
Next i


Thank you very much for any solution!
 
Any solution, if any, would depend entirely on what the other application
is, in particular whether it supports automation and depending on the app
(eg IE, Word) knowing where the text is you want to copy.

Regards,
Peter T
 
It is an old application developed in C and I can make selection and copy it
which I can see it on Excel Edit/Office Clipboard.
Problem is that I dont know how to automatically retrieve it from there and
paste it in the
ActiveSheet.

Thanks a lot for you answer!
 
If you can control all about putting into the clipboard, to put it into
cells two ways

Simple way -
Range("E7").PasteSpecial

with a lot more control -
First ensure the project has a reference to MS Forms, quick way is to add
(and remove) a userform

Sub test()
Dim s As String
Dim dob As DataObject
Set dob = New DataObject
dob.GetFromClipboard
s = dob.GetText
' now do whatever with s, eg
' Split() to parse into multiple lines or simply
Range("B12").Value = s
End Sub

Regards,
Peter T
 
Thank you so much Peter for your solution. It is what I need it but I still
have to
solve how to update my clipboard after I copy/paste fist string and I dont
know where and how to put your code in Excel.
If I put the code under a Click_Button I have to click it all the time which
is not convenient.
 
I don't understand what you are trying to do, where the text is being copied
from, which apps are you running, etc. You said something about using an old
C app to copy the text, how and from where are you running the C app, from
VBA? Or is your C-App automating Excel.

Regards,
Peter T
 
Dear Peter,

Sorry for my ambigous explanation and thank you a lot for your patience, it
will realy improve my VBA knowledge, quantity and quality work if will make
it functional.
I have to have both opened in the same time: the C Application (is not
automating VBA but I can manualy Copy text to Clipboard) and Excel.
I go to C App and manualy select+copy and Paste it to Excel.
This is a 5 copy/paste steps cycle that I have to make manualy the entire
workday and I cant imagine a better automatation than copy/paste in a loop
because the C Appl doesnt support VBA.

ActiveSheet.Cells(1,1)=clipboard(1)
ActiveSheet.Cells(1,2)=clipboard(2)
ActiveSheet.Cells(1,3)=clipboard(3)
ActiveSheet.Cells(1,4)=clipboard(4)
ActiveSheet.Cells(1,5)=clipboard(5)
..
..
..
..
ActiveSheet.Cells(10,1)=clipboard(51)
ActiveSheet.Cells(10,2)=clipboard(52)
ActiveSheet.Cells(10,3)=clipboard(53)
ActiveSheet.Cells(10,4)=clipboard(54)
ActiveSheet.Cells(10,5)=clipboard(55)

Therefore I need:
C App to PutInClipboard/ Excel to GetFromClipboard (update+transfer itself)
since I start my first manual selection till I close Excel
but without pressing a VBA control button everytime I want to
update/transfer the Clipboard.


Thank you again, I hope I this time I gave you a better understanding of
what I m looking for.
 
I appreciate you have tried to explain but afraid I am still not quite
following. It sounds like you have two app's which are totally independent
of one another, yet somehow you want them to communicate between one another

C-app copies text to clipboard
C-App tell VBA app to -
VBA gets text from clipboard and writes/pastes to a cell
VBA-app to tell C-App to go get the next one
repeat 50 (or 55?) times each time from and to new locations.

I would have though get your C app to do the whole thing. I don't know C but
I do know it can automate Excel and write to cells and I believe not very
difficult to write to the activesheet. Alternatively, get your VBA to copy
from the other app and write to cells. How easily it can copy from the other
app would depend on what the other app is and possibly from where in the
other app the text is. That might mean automation, or possibly unloved
SendKeys.

A third possibility, maybe get your C-app to copy the text,
get-from-clipboard, update (ie append) a text file, repeat 50 or 55 times.
When done get your VBA to get the text from the text-file, write to cells,
then delete the text-file

Regards,
Peter T
 
I know that I m not a good person to explain situation but I'll do my best.
Love you Peter for trying to save me.

I have a C Application that I use to create drawings and save them on a
server. (80 to 200 draings daily)
Indepently of that I have to save this layouts infos to Excel.

First step.

Type the customer home address in the C Appl to bring up a special map.
Before I save that address in C Apll, I'm selecting/copy it manualy to Excel
in the Column A.

Second step.
Type the drawing name in the C Appl.
Before I save that drawing name in C Apll, I'm selecting/copy it manualy to
Excel in the Column B.

(Same similar story with Step 3,4,5 coresponding to Columns C,D,E)

I would like my work-flow to look like this.

Before I would start C Appl, I would open my Excel and start a VBA Sub()
that transfers automatically (wihtout pressing any special
control button or shorcut) all the Selection/Copy that I will be making
starting that second till I will close Subroutine back.
I was thinking to use a keystroke subroutine but that doesnt pay because my
strings lenght/description are very difficult to be categorized in an
alogritm.


First step.

Type the customer home address in the C Appl to bring up a special map.
Before I save that address in C Apll, because I'm selecting/copy it manualy
to Clipboard our VBA subroutine will 'kick in' and it will export it
automaticaly to VBA.Clipboard(1) and will also paste it to Excel in the
Column A without asking any questions/conditions.

Second step.
Type the drawing name in the C Appl.
Before I save that drawing name in C Apll,because I'm selecting/copy it
manualy to Clipboard our VBA subroutine will 'kick in' and it will export it
automaticaly to VBA.Clipboard(2) and will also paste it to Excel in the
Column B without asking any questions/conditions.

(Another same similar story with Step 3,4,5 coresponding to C,D,E)


Example of a perfect scenario:
Type manualy in C App: 16 Avenue T, NYC . Select it manualy and right click
on "16 Avenue T, NYC" to Copy wich will automaticaly save it to Clipboard and
VBA subroutine to Excel into ActiveSheet.Cells(1,1)
Type manualy in C App: XJKL_Layout . Select it manualy and right click on
"XJKL_Layout" to Copy wich will automaticaly save it to Clipboard and VBA
subroute to Excel into ActiveSheet.Cells(1,2)

And so on till I'll stop the subroutine of copying my clipboard to Excel
automaticaly and come back to a regular computer behavior.

Thank you so so much for listening to me and for all of your efforts.
I'll appreciate any idea.
 
OK I think I understand what you are doing and how you want to do things.
The problem is with this step you have in mind

"
Type the customer home address in the C Appl to bring up a special map.
Before I save that address in C Apll, because I'm selecting/copy it manualy
to Clipboard our VBA subroutine will 'kick in' and it will export it
automaticaly to VBA.Clipboard(1) and will also paste it to Excel in the
Column A without asking any questions/conditions.
"

This implies somehow VBA will know when you have put some text into the
clipboard, and somehow it will know what the text refers to and where it
belongs (eg item 2.5), perform the paste action. I fear this is not the
answer you want but I really do not see any possibility of that ever
working. Theoretically it is possible for VBA to listen to keystrokes but
it's not a viable solution.

I think you need re-think the approach, maybe along the lines of what I
suggested previously. If you can reprogram your C-app here are two simple
possibilities -

1. Get your C-App to get the text from the clipboard and write it to a text
file.It would probably be better for the C-App to copy the text to a dialog
for you to confirm it is correct together with it's ID, eg item 2.5
When all 50+ done switch to your VBA.
In Excel/VBA there are at least two different ways to get the text file into
cells with one click. (Post back in a new thread to ask how VBA can get the
text file into cells)

2. Get your C-App to automate Excel. Before I got the impression you didn't
believe this is possible, but it certainly is. With this approach you could
have Excel visible and watch your C-App write the copied test to cells
without you even having to touch Excel.

Both the above of course assume you are able to reprogrammed your C-app, are
you able to do that?

Regards,
Peter T
 
Hi Peter,

You are more than a good friend for me.
The disscusion with you revealed me the fact that I dont know how to ask
people questions.
Thank you so much for the NO1 solution that you suggested today.I think this
is the only way to do it
because one way or another I have to force computer to make a refresh any
moment about the status of
API clipboard. The problem is getting more interesting than I though but my
programming skills are
very limited for the complexity of this little detail.

If you have any further suggestion let me know. I'll keep you updated if I
find any solution to my problem.
I was thinking that comparing 2 consecutive following clipboard values will
help me get a "Refresh" function
of the personalized clipboard.

Thanks a lot and please if you think that you have any kind of advices
related to programming, let me know!
 
Somebody build up a very good code for this problem. If anyone interested
just let me know. I would posted here but code is huge!

Thanks a lot to this community!!!!
 
Back
Top