Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 06-14-2023, 10:10 AM
gmaxey gmaxey is offline Export values from one embedded worksheet to another embedded worksheet Windows 10 Export values from one embedded worksheet to another embedded worksheet Office 2019
Expert
Export values from one embedded worksheet to another embedded worksheet
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Here is the code:


Code:
Option Explicit
#If VBA7 Then
  Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
  Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If

Sub UpdateNewBook()
Dim oILS As InlineShape
Dim oApp As Excel.Application
Dim lngIndex As Long
Dim lngRow As Long, lngCol As Long, lngPause As Long
Dim varUR
Dim oRng As Excel.Range
Dim oDoc1 As Document
Dim oDoc2 As Document
  'Define the source and target documents.
  'The two documents are open.  The source document is the active document.
  If Documents(1).Name = "Target.docm" Then
    Set oDoc2 = Documents(1)
  Else
    Set oDoc2 = Documents(2)
  End If
  Set oDoc1 = ActiveDocument
  Set oILS = oDoc1.InlineShapes(1)
  On Error GoTo Err_Handler
  'Write the row heading column and column data to a array.
  With oILS
    .OLEFormat.DoVerb wdOLEVerbHide
    'Launch Excel
    Set oApp = .OLEFormat.Object.Application
    With oApp
      varUR = .Workbooks(1).Worksheets(1).UsedRange.Value
      'Close Excel
      .Quit
    End With
  End With
  'Kill some time
  Sleep 500
  Set oILS = Nothing: Set oApp = Nothing
  DoEvents
  Sleep 500
  DoEvents
  Set oILS = oDoc2.InlineShapes(1)
  With oILS
    'Kill some more time.
    For lngPause = 1 To 5
      DoEvents
      Sleep 100
      DoEvents
    Next lngPause
    .OLEFormat.DoVerb wdOLEVerbHide
    'Kill some more time
    For lngPause = 1 To 5
      DoEvents
      Sleep 100
      DoEvents
    Next lngPause
    Set oApp = .OLEFormat.Object.Application
    With oApp
      Set oRng = .Workbooks(1).Worksheets(1).Columns(1)
      For lngIndex = 1 To UBound(varUR)
        On Error Resume Next
        'Find the row heading in the target sheet that matches the row heading in the source sheet
        lngRow = .WorksheetFunction.Match(varUR(lngIndex, 1), oRng, 0)
        If Err.Number = 0 Then
          For lngCol = 2 To UBound(varUR, 2)
            'Write the values in the correct row
            .Workbooks(1).Worksheets(1).Cells(lngRow, lngCol).Value = varUR(lngIndex, lngCol)
          Next lngCol
        Else
          Err.Clear
        End If
      Next lngIndex
      .Workbooks(1).Save
      .Quit
    End With
  End With
lbl_Exit:
  Set oApp = Nothing
  Exit Sub
Err_Handler:
  If Not oApp Is Nothing Then
    oApp.Quit
  End If
  MsgBox Err.Number & " - " & Err.Description
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Export values from one embedded worksheet to another embedded worksheet Link UserForm checkbox to corresponding shape on one worksheet and copy to 'template' worksheet kiwimtnbkr Excel Programming 23 10-08-2020 02:32 AM
Export Embedded Docs inside Word dhen21dx Word 2 03-25-2019 01:58 AM
How can I copy a worksheet and paste values to another new workbook ? DBenz Excel 1 01-26-2019 07:03 AM
Export embedded .txt or .csv file from Word bookmark to Access table field eric.okeefe Word VBA 4 08-29-2017 09:31 AM
Create Several PowerPoint Charts From One Embedded Excel worksheet Galapagos15 PowerPoint 0 10-30-2015 06:19 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:00 PM.


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