MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 1st, 2002, 07:00 AM   #1
nancyo
Board Regular
 
Join Date: Mar 2002
Location: Massachusetts, USA
Posts: 255
Default

I am just learning about excel and macros. Is it possible to write a macro from an excel spreadsheet to copy the spreadsheet into a word document? This would need to be from a specific file (in a certain directory) to a specific word doc (in a specific directory).

The trick is that the excel file would be used over and over with different information each time, and this information would need to go to the corresponding new word doc each time.???
nancyo is offline   Reply With Quote
Old Apr 1st, 2002, 07:31 AM   #2
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Do you really need a macro?

Can you just insert the Excel spreadsheet into Word using:

Insert|Object "Create from file" then browsing to your spreadsheet and making sure that "link to file" is checked? This will update your Word document whenever the spreadsheet is updated.

HTH
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Apr 1st, 2002, 07:37 AM   #3
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Hi,

This code copies the usedrange on Sheet1 from a specified file and pastes it into a specified Word document.

IMPORTANT: You need to go to Tools, References in the VB editor and make sure the Microsoft Word n.x Object Library is checked. n.x will depend on the version you're using - for Word 2000 it 9.0.

HTH,
Dan

Code:
Sub PasteToWord()
Dim wdApp As Word.Application, wdDoc As Word.Document

Dim strSourceFile As String, strDestFile As String


strSourceFile = "C:tempbook1.xls" 'Change to suit your needs

strDestFile = "C:tempyourdoc.doc" 'Ditto

'Open the Excel file
Workbooks.Open strSourceFile
ActiveWorkbook.Sheets("sheet1").UsedRange.Copy

'Open the Word document
Set wdApp = CreateObject("Word.Application")
wdApp.Documents.Open strDestFile
wdApp.Selection.Paste

End Sub
dk is offline   Reply With Quote
Old Apr 1st, 2002, 08:51 AM   #4
nancyo
Board Regular
 
Join Date: Mar 2002
Location: Massachusetts, USA
Posts: 255
Default

Mark - this implies that each time the word doc is updated, it overwrites the current info. I need a separate file each time from excel to word. ?

Dan - where do I put this code? in the excel file as a module? I tried it that way, when i click run is does something, but does not create the file I need. Also, the source file and dest file will change with each set of data. Is this possible with the code as written? Please excuse my stupid questions, but this is my second week learning (all self taught) this stuff...
nancyo is offline   Reply With Quote
Old Apr 1st, 2002, 08:55 AM   #5
lenze
MrExcel MVP
 
lenze's Avatar
 
Join Date: Feb 2002
Location: Helena, MT
Posts: 13,690
Default

If you create a Word Template that has links to the Excel sheet, it will open as a NEW document each time and update with the current contents of the Excel sheet.
lenze is offline   Reply With Quote
Old Apr 1st, 2002, 09:00 AM   #6
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Quote:
On 2002-04-01 07:51, nancyo wrote:
Mark - this implies that each time the word doc is updated, it overwrites the current info. I need a separate file each time from excel to word. ?
Yup, you're correct. I missed the phrase "new Word" in your original post. I'd follow the VBA code or lenze's suggestions here.
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Apr 1st, 2002, 09:23 AM   #7
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Nancy,

What area will of the Excel worksheet will you be copying? Will it be the same each time? Do you want the user to be able to select both source and destination files e.g. with a standard Open dialog box? Or do you want a new Word document created each time you run this macro?

Regards,
Dan
dk is offline   Reply With Quote
Old Apr 1st, 2002, 09:45 AM   #8
nancyo
Board Regular
 
Join Date: Mar 2002
Location: Massachusetts, USA
Posts: 255
Default

Dan - the excel folder has several spreadsheets. Only one needs to be copied into word, and will be the same each time.

The excel file will be saved as a different filename with each new set of data. From there, I want to be able to just copy one of the spreadsheets into a word document, which will also have a new filename (either a template which keeps bening renamed, or?).

I do not know what an Open dialog box is (I am SO new to this). If the tech could select a source and destination, what about filenames? Would they need to be created in word ahead of time?

Ideally, the data is generated and saved into a specific spreadsheet in excel (to be resaved as another filename with each new set of data).

Once this is done, rather than copying and pasting by hand into a new word document, I would like to be able to have either a macro or some other way to do this automatically. There are way too many techs errors, and I want to eliminate this problem.

I apologize for my ignorance!!! I am leaving for the day...any resonses will be tomorrow. THANKS TO ALL!!!
nancyo is offline   Reply With Quote
Old Apr 1st, 2002, 04:25 PM   #9
Jack in the UK
Board Regular
 
Join Date: Feb 2002
Posts: 3,065
Default

Hi Nancy

Yuuuck Did i hear that WORD thingy...???

PK i hat word for no reason bar its not excel and i WONT allow it on any PC i go near...

But thats not the point.. check for an EXCEL file called Samples (the world will hit find files Samples.xls best i can remember thats what its called, suggest S*.xls search just in case)

I have sheets one has all the code to trans from A to B in Office Excel to Word is there for sure if Excel was loaded correctly.. this will get you started...

Now you have the text over.. the nasty stuff comes into plat WordBasic not VBA.. and ive no idea at that.. Excel can com and Word but?? Not got a cluse..

MY opinion is to didtroy word and do it all in Excel Shes muh nicer and better lloking, and can do all Word can withthe addition of Math.. and i fancy her!

If you need more hlep im sure this case be solved you producing letters or a report??? i guess..

__________________
Free Excel based Web Toolbar available here.

Jack in the UK
J & R Excel Solutions
"making Excel work for you"
Jack in the UK is offline   Reply With Quote
Old Apr 4th, 2002, 02:37 PM   #10
nancyo
Board Regular
 
Join Date: Mar 2002
Location: Massachusetts, USA
Posts: 255
Default

Dan - I have tried many variations on a theme with your code. Any suggestions?
nancyo is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 02:55 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes