![]() |
|
#1
|
|||
|
|||
![]()
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!!!!! ![]() |
#2
|
|||
|
|||
![]()
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." |
#3
|
|||
|
|||
![]()
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 |
![]() |
|
![]() |
||||
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 |