Solved

Copy into the clipboard and paste from clipboard into cell of currently selected table.

Posted on 2011-02-14
14
269 Views
Last Modified: 2012-05-11
Dear Experts:

I would like to incorporate two code snippets in a couple of macro codes. I wonder whether you could help me out with then.

Code snippet 1:
A number with the following make-up (##-###-##-##) is to be selected in cell (15,1) of the currently selected table and copied into the clipboard.

Code snippet 2:
The clipboard is to be emptied and pasted into the currently selected table ...
in cell (16,2) after the 28th character.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
  • 5
  • 4
  • 2
  • +1
14 Comments
 
LVL 8

Expert Comment

by:ragnarok89
ID: 34888314
You could just turn on Macro recording, perform the actions you describe, and then turn off Macro recording. A module would auto created containing the code version of the actions you just performed. You could then tweak it to your liking.

Al
0
 

Author Comment

by:AndreasHermle
ID: 34889509
Dear ragnarok89:

Thank you very much for your swift answer. I am aware that I could record it, but - to be honest with you - I would like a professional solution. The macro recorder often records things that in a strict programmer sense is no good.

Regards, Andreas
0
 

Author Comment

by:AndreasHermle
ID: 34895244
Dear all:

only code snippet 2 is relevant. In the meantime I found a solution for code snippet 1.

Here again my requirements for the code snippet:

The clipboard is to be emptied and pasted into the currently selected table ...
in cell (16,2) after the 28th character.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34922107
Can you give me an example?

Sid
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 350 total points
ID: 34922132
If I understood your query then this is what you need?

Sub Sample()
    Sheets("Sheet1").Cells(16, 2).Value = Mid(Sheets("Sheet1").Cells(16, 2).Value, 1, 28) & _
                                          Format(Sheets("Sheet1").Cells(15, 1), "##-###-##-##") & _
                                          Mid(Sheets("Sheet1").Cells(16, 2).Value, 17)
End Sub

Open in new window


Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34922136
Please replace "Sheet1" with the respective Sheet Name.

Sid
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 150 total points
ID: 34922696
Commands for accessing the clipboard can be found here

http://www.cpearson.com/excel/Clipboard.aspx

Saqib
0
 

Author Comment

by:AndreasHermle
ID: 34932304
Hi Sid,  

thank you very much for your quick support.  I guess there must be some understanding here. My question refers to a Word problem. You are referring to Excel in your post.
But thank you anyway for the  time taken.

Regards,  Andreas
0
 

Author Comment

by:AndreasHermle
ID: 34932313
Hi Sagib:

thank  you very much for your swift help. This link is a valuable resource, thank you. But, as a matter of  fact, my question is a word problem not an Excel problem.

Thank you.

Regards, Andreas
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 34932492
You can make it work in Word by adding a reference to microsoft forms.

To do that, in VBA, go to

tools > references > browse

and select

c:\windows\system32\FM20.DLL

and make sure that microsoft forms 2.0 is in the list and checked.

Saqib
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34932549
Andreas: My apologies for not checking that but then again the logic remains the same in word table as well.

Directly assign the value from one cell of the table to the another. You don't need a clipboard for it.

Sid
0
 

Author Closing Comment

by:AndreasHermle
ID: 34939097
Hi,

thank you very much to both of you for your professional. Regards, Andreas
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now