Transfer Word string to XL

  • Although I am a relatively experienced user of Access and Excel and have used VBA with both extensively, I feel like a complete novice when I am in Word VBA.


    All I want to do is to (in VBA) is move to the beginning of my Word document, select the first line of text (a reference string) and convert this to a string variable that I can post to an Excel cell.


    I have no idea how to move to the beginning of the document, but if I did, the best that I can come up with is: xString = selection.copy, which of course does not work.


    Can you help? :?

  • Re: Transfer Word string to XL


    I have now solved this by using the clipboard (method and code from word.mvps.org).


    However, I still cannot currently find VBA code for 'go to beginning of doc'. Ah well .... I will search on the web ...

  • Re: Transfer Word string to XL


    Code
    Selection.HomeKey Unit:=wdStory


    Here's a tip for figuring this stuff out yourself. Start recording a macro, do whatever it is you want to do, then stop recording and look at the resulting code. In your case, I'm sure you knew that Ctrl+Home brings you to the beginning of a document, so record yourself hitting that key combo, then look at the code and you should see the above line. That's what I get in Word 2000 anyway, assuming it's the same in other versions.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!