I am trying to make a push button that can copy text from multiple cells “I9 - I35.” I already have the push button created, I just need a macro to assign to it. I am very new to this type of stuff so any help would be appreciated. Thanks.
Do you want paste the content into a new, empty RTF document or into an existing one? (Where you want to paste the content in an existing RTF document to?)
.
In my opinion: The RTF is a never standardized, abandoned, obsolete, foreign file format for poorly formatted texts. Do not use it.
Ok, since you put it that way it would just be .doc document then. I do not need the button to paste for me, I just need it to copy the cells I provided and I will paste manually into the .doc.
The binary MS .doc file type IS a never standardized, obsolete, and foreign file format too.
Then: select I9 - I35 cell range and Ctrl-C, Ctrl-V. The paste option depends on the features of the target software. If it is the LO too, the use the Paste Special feature.
Ok. Yes I am very much aware of cntrl C + V. I am trying to create a button though, I do not want alternatives. IS THAT possible?
It depends.
- In what way shall the macro take information WHAT
SheetCellRange
is to be copied? Will it always beI9:I35
? If so in which one of the sheets? (Most spreadsheet documents have more than one.) - In what way shall the target document be made accessible to the macro?
- In what way will the postion to which the copy shall be pasted inside the target document be specified? By interactive selection? Via a passed parameter?
- Shall the pasted result be a table again? What type of table? (Tables in Text documents ar very different from ranges of spreadsheets.) Or shall, e.g, a tab-separated sequence be created?
- What programming skills are to your disposition? (Or do you expect somebody else to do it for you?)
-
Yes, always I9:I35. It is the first sheet.
-
I don’t know what this means.
-
I do not know either. I need to paste unformatted text into my target document.
-
I do not want the pasted result to be a table again. Just text.
-
I have zero programming skills and I have no idea how to do this. I posted this to ask for help how to code it so yeah any help would be appreciated here.
A macro can only work with documents it has a grip on. It would have it if it creates the document itself. It may get it if the document is of a type LibO can handle, and the user opened it in advance and passes the needed info to the macro.
(and so on)
It actually seems there aren’t any related skills.
Rest assured that I (we) do not mean to be unkind.
But ask.libreoffice.org is a help site. We can’t offer free custom solutions for tasks that aren’t even described in enough detail.
Once again: Try to solve your problem without a macro.
If you insist on a macro, and are eager to start with very old-fashioned means of Basic, You may want to study the attachment.
ask93471veryStrangeSpecialExport.ods (12.9 KB)
Ok, thanks for the help and information.
A thread on the problem to find the target document (especially the question, is it already open). But it is in german language…
@Wanderer As far as I understand the translation from German, does it discuss the technique used in the OpenDocument() function of the Misc module of the Tools standard library?
Perhaps you use something like this as a starting point?
Sub copyTextsFromCellsToWriter
Const SOURCE_RANGE = "I9:I35"
Dim oCellRangeByName As Variant
GlobalScope.BasicLibraries.LoadLibrary("Tools")
oCellRangeByName = ThisComponent.getSheets().getByIndex(0).getCellRangeByName(SOURCE_RANGE)
CreateNewDocument("swriter").getText().setString(CreateUNOService("com.sun.star.sheet.FunctionAccess").callFunction("TEXTJOIN", Array(" ", 0, oCellRangeByName)) )
End Sub
This was able to open a new document for me, but that’s not actually what I was looking to do. I was looking to have the copied text from I9:I35 be copied to the clipboard, therefore I would be able to paste into another document with “right click-paste unformatted text”. Thanks for the help.
I intentionally used the expression “as a starting point” - I give you the opportunity in this new document to write a macro “select all, cut to clipboard, close the document without saving”. When you combine these two pieces of code, you’ll get exactly what you’ve described so far - your clipboard will contain the text from the specified cells, ready to be pasted into the right place.
No, we are not kidding, we want you to start doing it yourself. Each of those who took part in this discussion is able to write several different scripts to solve the described problem. We just don’t want to do it for you.
The problem discussed there is the question, if the destination file einritte.ods
is already open, so they check all open windows. The used funktion is from Tools lib, so you have to load this before use.
…or copy the code of that function (and all others used) into your module
Oh man I should’ve known you guys were talking business… i guess ill take my lazy ass somewhere else LOL i guess everyone needs a place to project there massive egos somewhere so ill let you guys circle jerk each other off in here. Thanks bud!
Is there any place where you are welcome with this arrogant attitude?
You describe from the beginning not nearly exactly, actually almost not at all and otherwise misleading (“RTF”), what you actually want. You are basically wasting the time of those who are trying to help you anyway. And then you insult these people. Bye!
Sub prepareMyCopyAction()
ThisComponent.CurrentController.select(ThisComponent.Sheets(0).getCellRangeByName("I9:I35"))
End Sub