Macros hate me :(

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

pavja2
Posts: 29
Joined: Mon Oct 05, 2009 9:31 pm UTC

Macros hate me :(

Postby pavja2 » Mon Oct 05, 2009 9:39 pm UTC

I am clinging to the desperate hope that whoever designed Word 2003's Macro recorder visits this site frequently (note: If this is you, I recommend helping me...or locking your doors every night).
I am trying to write a Macro that searches through a word document and selects everything that is heading 2. It the copies the selected text and pastes it into an excel spreadsheet.

If this is possible how should I go about it, if it is not who should I mail the bobcat to?
http://xkcd.com/325/

pavja2
Posts: 29
Joined: Mon Oct 05, 2009 9:31 pm UTC

Re: Macros hate me :(

Postby pavja2 » Mon Oct 05, 2009 11:54 pm UTC

Apparently the 32 of you all who have looked at my post so far hate me too.
;)

User avatar
poxic
Eloquently Prismatic
Posts: 4756
Joined: Sat Jun 07, 2008 3:28 am UTC
Location: Left coast of Canada

Re: Macros hate me :(

Postby poxic » Tue Oct 06, 2009 12:04 am UTC

Yes, that's totally the reason we haven't answered. It isn't at all because we read the question, didn't know the answer, and left it for someone who might. :roll:

/no idea how to help you
//welcome to the fora
///the boards here are not usually busy enough to get you an answer in two hours
The Supreme Ethical Rule: Act so as to elicit the best in others and thereby in thyself.
- Felix Adler, professor, lecturer, and reformer (13 Aug 1851-1933)

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: Macros hate me :(

Postby Cosmologicon » Tue Oct 06, 2009 12:16 am UTC

I assumed you were talking about C macros from the title.

fazzone
Posts: 186
Joined: Wed Dec 10, 2008 9:38 pm UTC
Location: A boat

Re: Macros hate me :(

Postby fazzone » Tue Oct 06, 2009 2:00 am UTC

As did I.
*/

User avatar
Vault
Posts: 169
Joined: Mon Nov 10, 2008 5:00 pm UTC
Location: Just past the event horizon
Contact:

Re: Macros hate me :(

Postby Vault » Tue Oct 06, 2009 2:34 am UTC

I was expecting lisp.

User avatar
scarecrovv
It's pronounced 'double u'
Posts: 674
Joined: Wed Jul 30, 2008 4:09 pm UTC
Location: California

Re: Macros hate me :(

Postby scarecrovv » Tue Oct 06, 2009 3:39 am UTC

Vault wrote:I was expecting lisp.

Same here.

You might want to change the title to make it more specific.

sje46
Posts: 4730
Joined: Wed May 14, 2008 4:41 am UTC
Location: New Hampshire

Re: Macros hate me :(

Postby sje46 » Tue Oct 06, 2009 3:48 am UTC

Hey, I learned about macros!

I'd have to go on a different machine to help you.

Guys: a macro is a program that changes a word document according to a certain formula. You can record a macro by pressing a button on the developer ribbon (you'd have to enable that), and just typing, changing the font, whatever you want to do to the text. It records all you did in a program, and you can apply this program to another document or high lighted text.
I think it is written in Visual Basic.
I've only used macros once, in 2007. I'll try to help you out though.
General_Norris: Taking pride in your nation is taking pride in the division of humanity.
Pirate.Bondage: Let's get married. Right now.

CortoPasta
Posts: 38
Joined: Fri Aug 15, 2008 5:51 pm UTC

Re: Macros hate me :(

Postby CortoPasta » Tue Oct 06, 2009 2:30 pm UTC

Check out stackoverflow.com, they might have a more timely answer. If it was an excel macro, I could help you :p

User avatar
TNorthover
Posts: 191
Joined: Wed May 06, 2009 7:11 am UTC
Location: Cambridge, UK

Re: Macros hate me :(

Postby TNorthover » Tue Oct 06, 2009 5:52 pm UTC

Vault wrote:I was expecting lisp.

I was hoping for lisp, but expecting what I thought at the time was the worst -- C. I was wrong on both counts.

Philwelch
Posts: 2904
Joined: Tue Feb 19, 2008 5:33 am UTC
Location: RIGHT BEHIND YOU

Re: Macros hate me :(

Postby Philwelch » Tue Oct 06, 2009 6:36 pm UTC

pavja2 wrote:I am clinging to the desperate hope that whoever designed Word 2003's Macro recorder visits this site frequently (note: If this is you, I recommend helping me...or locking your doors every night).
I am trying to write a Macro that searches through a word document and selects everything that is heading 2. It the copies the selected text and pastes it into an excel spreadsheet.

If this is possible how should I go about it, if it is not who should I mail the bobcat to?
http://xkcd.com/325/


I would take this as an object lesson in never, ever using Word, Microsoft products in general, or proprietary data formats in general. Marked up plain text would be simple to design this kind of routine for using 30 year old tools. It's too bad the latest offerings from Microsoft don't even match the functionality of awk from 1977.
Fascism: If you're not with us you're against us.
Leftism: If you're not part of the solution you're part of the problem.

Perfection is an unattainable goal.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Macros hate me :(

Postby You, sir, name? » Tue Oct 06, 2009 6:41 pm UTC

Philwelch wrote:I would take this as an object lesson in never, ever using Word, Microsoft products in general, or proprietary data formats in general. Marked up plain text would be simple to design this kind of routine for using 30 year old tools. It's too bad the latest offerings from Microsoft don't even match the functionality of awk from 1977.


That is true, but does awk come with a talking animated paper clip that pesters you with barrages of irrelevant suggestions?
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
OmenPigeon
Peddler of Gossamer Lies
Posts: 673
Joined: Mon Sep 25, 2006 6:08 am UTC
Contact:

Re: Macros hate me :(

Postby OmenPigeon » Wed Oct 07, 2009 3:49 am UTC

You, sir, name? wrote:That is true, but does awk come with a talking animated paper clip that pesters you with barrages of irrelevant suggestions?

No, but emacs does: M-x C-x stockholm-syndrome

(May not be a valid emacs command. But it should be.)
As long as I am alive and well I will continue to feel strongly about prose style, to love the surface of the earth, and to take pleasure in scraps of useless information.
~ George Orwell

User avatar
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: Macros hate me :(

Postby thoughtfully » Wed Oct 07, 2009 12:55 pm UTC

You could try OpenOffice as a substitute for Word/Excel. It uses Python for its macros!

You can even use COM to talk to Excel from Python. Sometimes Excel is harder to ditch than Word. It sounds like you are stuck with a pile of Word documents, though. You could try OpenOffice and see what success you have at importing them. Maybe you can use Word to export them first, say to RTF, if that's useful. It sounds like you don't need perfect fidelity, anyway, just that H2 text.
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

User avatar
Hawknc
Oompa Loompa of SCIENCE!
Posts: 6986
Joined: Mon Oct 02, 2006 5:14 am UTC
Location: Melbourne, Australia
Contact:

Re: Macros hate me :(

Postby Hawknc » Wed Oct 07, 2009 2:06 pm UTC

You guys are spectacularly unhelpful. A lot of us really don't have a choice in the tools we have to use, and positing absurd workarounds through multiple programs is a lot less useful than simply not posting if you don't have anything helpful to say.

Anyway. I'm not about to write a whole macro (I do enough of that at work), but this line should give you a starting point:

Selection.Find.Style = ActiveDocument.Styles("Heading 2")

Happy to help tomorrow if you need more help than this, but it's 1AM here so that's all I'm up for tonight. ;)

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: Macros hate me :(

Postby Cosmologicon » Wed Oct 07, 2009 6:31 pm UTC

Hawknc wrote:You guys are spectacularly unhelpful. A lot of us really don't have a choice in the tools we have to use, and positing absurd workarounds through multiple programs is a lot less useful than simply not posting if you don't have anything helpful to say.

The OP complained when we didn't post anything. All the useless replies are an object lesson. ;-)

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Macros hate me :(

Postby You, sir, name? » Wed Oct 07, 2009 6:45 pm UTC

Cosmologicon wrote:
Hawknc wrote:You guys are spectacularly unhelpful. A lot of us really don't have a choice in the tools we have to use, and positing absurd workarounds through multiple programs is a lot less useful than simply not posting if you don't have anything helpful to say.

The OP complained when we didn't post anything. All the useless replies are an object lesson. ;-)


To be fair, even if he didn't, there's a large degree of likelihood that this fate would be bestowed upon the thread:

gmalivuk wrote:
Hawknc wrote:This is the easiest question ever asked on the forum, and you guys turn it into a two-page debate.
...Don't ever change.

I think there was a discussion about this tendency awhile back. If someone's obviously asking for homework help, or it's a stupid (or at least stupidly worded) question, most of us feel pretty justified in horribly overcomplicating our responses, just to fuck with the original poster.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Cleverbeans
Posts: 1378
Joined: Wed Mar 26, 2008 1:16 pm UTC

Re: Macros hate me :(

Postby Cleverbeans » Thu Oct 08, 2009 3:17 am UTC

pavja2 wrote:I am trying to write a Macro that searches through a word document and selects everything that is heading 2. It the copies the selected text and pastes it into an excel spreadsheet.


I don't use word much, so if you can explain how to set something to "heading 2" manually, or post the contents of your macro recorder after changing something to "heading 2" I should be able to resolve it.
"Labor is prior to, and independent of, capital. Capital is only the fruit of labor, and could never have existed if labor had not first existed. Labor is the superior of capital, and deserves much the higher consideration." - Abraham Lincoln

sje46
Posts: 4730
Joined: Wed May 14, 2008 4:41 am UTC
Location: New Hampshire

Re: Macros hate me :(

Postby sje46 » Thu Oct 08, 2009 3:38 am UTC

Spoiler:
Hawknc wrote:You guys are spectacularly unhelpful. A lot of us really don't have a choice in the tools we have to use, and positing absurd workarounds through multiple programs is a lot less useful than simply not posting if you don't have anything helpful to say.
Truth. I've noticed that a lot of people here are a bit elitist when it comes to technology. If I ask how to log conversations on Chatzilla, they'd tell me to install X chat instead. If I ask how to connect to Telnet on Vista, they'd tell me to get Linux instead. It's a bit irritating.
You, sir, name? wrote:To be fair, even if he didn't, there's a large degree of likelihood that this fate would be bestowed upon the thread:

gmalivuk wrote:
Hawknc wrote:
This is the easiest question ever asked on the forum, and you guys turn it into a two-page debate.
...Don't ever change.

I think there was a discussion about this tendency awhile back. If someone's obviously asking for homework help, or it's a stupid (or at least stupidly worded) question, most of us feel pretty justified in horribly overcomplicating our responses, just to fuck with the original poster.
Cosmologicon wrote:
Hawknc wrote:You guys are spectacularly unhelpful. A lot of us really don't have a choice in the tools we have to use, and positing absurd workarounds through multiple programs is a lot less useful than simply not posting if you don't have anything helpful to say.

The OP complained when we didn't post anything. All the useless replies are an object lesson. ;-)


To be fair, even if he didn't, there's a large degree of likelihood that this fate would be bestowed upon the thread:

gmalivuk wrote:
Hawknc wrote:This is the easiest question ever asked on the forum, and you guys turn it into a two-page debate.
...Don't ever change.

I think there was a discussion about this tendency awhile back. If someone's obviously asking for homework help, or it's a stupid (or at least stupidly worded) question, most of us feel pretty justified in horribly overcomplicating our responses, just to fuck with the original poster.


What can I say? Gmal is an idiot. If someone is asking someone to do their homework for them, then that thread should be locked. And their is nothing wrong with helping someone out with his homework; that's a very good thing. The problem is that it's wrong to do their homework for them, because that person won't learn anything. Asking for help with searching for a Heading 2 does not really sound like it's homework. It might be a very small part of a homework assignment, but it's not really academically dishonest, if he can't find the answer himself. And I don't really see how the question is stupid either. And if it is stupid, just ask the OP to clarify. There is no need to be a douche about it.
General_Norris: Taking pride in your nation is taking pride in the division of humanity.
Pirate.Bondage: Let's get married. Right now.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Macros hate me :(

Postby You, sir, name? » Thu Oct 08, 2009 9:39 am UTC

sje46 wrote:What can I say? Gmal is an idiot. If someone is asking someone to do their homework for them, then that thread should be locked. And their is nothing wrong with helping someone out with his homework; that's a very good thing. The problem is that it's wrong to do their homework for them, because that person won't learn anything. Asking for help with searching for a Heading 2 does not really sound like it's homework. It might be a very small part of a homework assignment, but it's not really academically dishonest, if he can't find the answer himself. And I don't really see how the question is stupid either. And if it is stupid, just ask the OP to clarify. There is no need to be a douche about it.


The quote is badly formulated, to be fair. It's when someone tries to trick the forum into doing their homework/job they get horrible over complication of doom. If someone actually admits that it's their homework, it is much less likely that happen. Asking about problems you encounter doing your homework is usually taken pretty well, but the sort of query that's verbatim copypasta from the problem section of some textbook, with a question mark added to the end usually gets the hose.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

halbarad
Posts: 394
Joined: Mon Dec 08, 2008 11:49 am UTC

Re: Macros hate me :(

Postby halbarad » Thu Oct 08, 2009 1:51 pm UTC

OP: Have you tried to manually record the function with the Macro recorder for just one instance of copying the text into excel and the use Hawknc's suggestion for finding the other bits of text you need. Put it all in a loop or some other form of iteration and your done.

pavja2
Posts: 29
Joined: Mon Oct 05, 2009 9:31 pm UTC

Re: Macros hate me :(

Postby pavja2 » Mon Oct 12, 2009 11:27 pm UTC

Ok everyone, yahoo answers pulled through, it's funny how elitist XKCD and Stack Overflow people can be...:) trust me If I could convince everyone on my debate team who would be using this macro to switch to open office it would be great :)

This was the solution:

Code: Select all

Sub MagicFlow1()
  Dim doc As Document, par As Paragraph, str As String
  Dim xlApp As Excel.Application, wbk As Excel.Workbook
  Dim sht As Excel.worksheet, rng As Excel.Range
  Set doc = ActiveDocument
  Set xlApp = CreateObject("Excel.Application")
  xlApp.Visible = True
  Set wbk = xlApp.Workbooks.Add
  Set sht = wbk.Sheets(1)
  Set rng = sht.Range("A1")
  For Each par In doc.Paragraphs
    If par.Style = "Heading 2" Then
      str = par.Range.Text
      rng.Value = Left(str, Len(str) - 1)
      Set rng = rng.Offset(1, 0)
    End If
  Next
End Sub



However if you all are up to another MUCH harder programming challenge here it is:

Using the above macro, how can I modify it so that whenever it comes across "Heading 1" it creates a new sheet in the same excel document with the same name as whatever is heading 1 then copies the "heading 2" text between that and the next instance of "Heading 1" into that new sheet?



For example, the document looks like this (with bold being heading 1 and italics heading 2)
I LIKE CHEESE
Cheese reminds me of a french girl I used to date...
she was very nice but she broke up with me after I stole her car...
She was a failure...
Her mom fed her to her pet raptor last night

I am going to the funeral now
hopefully they will have cheese
i really do like cheese




And the result will be two sheets in a single excel work book:
The first entitled "I LIKE CHEESE"
with the content
"Cheese reminds me of a french girl I used to date" on the first row
and "She was a failure" on the second row.

And another sheet called "I am going to the funeral now"
with the content "hopefully they will have cheese"


I doubt this is even possible, even for you XKCD readers...but I won't be dissapointed If you prove me wrong.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Macros hate me :(

Postby You, sir, name? » Mon Oct 12, 2009 11:46 pm UTC

pavja2 wrote:Pout whine sulk, nobody will do my work for me.

Here's some more work of mine for you to do for me that I bet you is too difficult for you.


I think your difficulties boil down to the following: Nobody wants to code in BASIC. Many people wouldn't do this even if you offered them money instead of tried to trick them into doing it, because BASIC is nasty.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
phlip
Restorer of Worlds
Posts: 7573
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Macros hate me :(

Postby phlip » Thu Oct 15, 2009 7:02 am UTC

What you're asking for is pretty easy, anyway...

You already have a loop that looks for headings... just add another check in that loop for if it's "Heading 1", and if it is, add a new sheet, set sht to point to it, set its name and reset rng to A1... then the next Heading 2 paragraph will end up on the new sheet.

Simple.

And yes, Y,s,n is right... we're not going to do your job for you, just like we're not going to do people's homework for them. We're happy to help if you want to learn to do it yourself, though.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

pavja2
Posts: 29
Joined: Mon Oct 05, 2009 9:31 pm UTC

Re: Macros hate me :(

Postby pavja2 » Thu Oct 15, 2009 10:23 pm UTC

Well thanks for the help...I appreciate it. And while I disagree with your "we're not here to do your work for you" stuff, I am glad for any help. That's what the Internet is for, so that only one person has to figure something out and then the rest of the world can benefit without doing the exact same stuff. It's a way to diffuse the role of raw knowledge and increase the importance of ingenuity. The set of macros that this would be part of would revolutionise the world of policy debate, and it's not like I'd charge for them. So if you do know the solution share, if not I'll post it when I figure it out.

User avatar
RoadieRich
The Black Hand
Posts: 1037
Joined: Tue Feb 12, 2008 11:40 am UTC
Location: Behind you

Re: Macros hate me :(

Postby RoadieRich » Sat Oct 17, 2009 4:01 am UTC

pavja2 wrote:That's what the Internet is for, so that only one person has to figure something out and then the rest of the world can benefit without doing the exact same stuff.

If one person solved all the problems without teaching anyone else, what happens when that person dies?
Some problems require ingenuity. Some just need people to actually stop for a moment and think, if I can do X, and Y is like X, can I do Y with a little bit more information?

And information is what the internet is there for.
73, de KE8BSL loc EN26.

sje46
Posts: 4730
Joined: Wed May 14, 2008 4:41 am UTC
Location: New Hampshire

Re: Macros hate me :(

Postby sje46 » Sat Oct 17, 2009 5:44 am UTC

and porn.
General_Norris: Taking pride in your nation is taking pride in the division of humanity.
Pirate.Bondage: Let's get married. Right now.

User avatar
Cleverbeans
Posts: 1378
Joined: Wed Mar 26, 2008 1:16 pm UTC

Re: Macros hate me :(

Postby Cleverbeans » Sat Oct 17, 2009 2:33 pm UTC

RoadieRich wrote:Some problems require ingenuity.


On the other hand, some problems require wading through weak documentation in an archaic language for a depreciated API until you get lucky and stumble upon the right answer, which is still actually faster than doing the work by hand because the base application really really sucks. I think if you've got the knowledge of how solve a quick and dirty problem in VBA then there is a moral obligation to provide it to someone for their homework/work just because it's VBA. If a school assigned it they obviously don't care about their students success and should be expecting falsified results; if it's for work basic pity, compassion, and the golden rule compel me to do it.

I've got a theory that it would be easier to teach an inverted midget to program on an abacus and output to an etcha-sketch "monitor" with their toes then to do it in VBA, but I haven't tested it because Gary Coleman won't return my calls. So much for American dominance in the sciences...
"Labor is prior to, and independent of, capital. Capital is only the fruit of labor, and could never have existed if labor had not first existed. Labor is the superior of capital, and deserves much the higher consideration." - Abraham Lincoln


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 9 guests