Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-18-2011, 08:54 PM
educpara58 educpara58 is offline Inserting excel spreadsheet into word doc Windows 7 32bit Inserting excel spreadsheet into word doc Office 2007
Novice
Inserting excel spreadsheet into word doc
 
Join Date: Jul 2011
Posts: 1
educpara58 is on a distinguished road
Default Inserting excel spreadsheet into word doc

How do you insert a self-generating (random numbers) spreadsheet into a Word document so that the document has different numbers each time it is opened?
eg Billy has (random number) marbles and Tom has (random number) marbles. How many do they have all together?

I would like the spreadsheet to be invisible as well and would rather not link the spreadsheet to the word doc.

Help please!!!!!

Reply With Quote
  #2  
Old 07-28-2011, 12:02 AM
Catalin.B Catalin.B is offline Inserting excel spreadsheet into word doc Windows Vista Inserting excel spreadsheet into word doc Office 2007
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

You can start with this macro for the sample document.

Sub UpdateEmbeddedXLSX()
Dim workbook As InlineShape
For Each workbook In ActiveDocument.InlineShapes
With workbook
If .Type = wdInlineShapeEmbeddedOLEObject Then
''# Excel.Sheet.12 for Excel 2007
If .OLEFormat.ClassType = "Excel.Sheet.12" Then
''# Open Object as spreadsheet
.OLEFormat.DoVerb wdOLEVerbPrimary
''# If you want, you can also do any updates here like
.OLEFormat.Object.ActiveSheet.Cells(2, 2).Value = ".1"
''# Nasty - but it works - SendKeys
SendKeys "{ESC}", True
End If
End If
End With
Next
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub


If you want the macro to run at opening the document, you have to do this settings
To make an existing macro execute whenever you open a document in Microsoft Word, rename it "AutoOpen" by clicking "View," "Macro," "View Macros ...," then choosing the existing macro and clicking "Edit." In the resulting screen, edit the two top lines in the VBA code window to replace the current macro name with "AutoOpen."
Attached Files
File Type: docx New Document Microsoft Office Word.docx (16.9 KB, 7 views)
Reply With Quote
  #3  
Old 07-28-2011, 01:22 AM
Catalin.B Catalin.B is offline Inserting excel spreadsheet into word doc Windows Vista Inserting excel spreadsheet into word doc Office 2007
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

Sorry, the other macro has some errors, this works:

Private Sub CommandButton1_Click()

Dim workbook As InlineShape
For Each workbook In ActiveDocument.InlineShapes
Application.ScreenUpdating = False
With workbook

On Error Resume Next

If .Type = wdInlineShapeEmbeddedOLEObject Then
''# Excel.Sheet.12 for Excel 2007
If .OLEFormat.ClassType = "Excel.Sheet.12" Then
''# Open Object as spreadsheet
.OLEFormat.DoVerb wdOLEVerbPrimary
''# If you want, you can also do any updates here like
.OLEFormat.Object.ActiveSheet.Cells(2, 2).Value = ".1"
''# Nasty - but it works - SendKeys
SendKeys "{ESC}", True
.OLEFormat.Object.Close

End If
End If
End With
Next
Application.ScreenUpdating = True
End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedded Excel Spreadsheet in Word Loses Ribbon amoncur Word 0 07-03-2010 09:22 PM
Word Fill-in form with Excel spreadsheet karik Word 0 01-11-2010 08:45 AM
Auditing on Excel and Spreadsheet documents paulmills Office 0 12-08-2009 01:13 PM
How do I use an Excel form to populate and Excel spreadsheet apostht Excel 0 05-21-2006 11:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:18 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft