Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2016, 08:54 PM
gmayor's Avatar
gmayor gmayor is offline worksheetfunction not working when controlling excel from word. Windows 10 worksheetfunction not working when controlling excel from word. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It doesn't work for me either - but the following does. Note that Paul's code will leave an invisible instance of Excel running, with a worksheet containing the pasted values, which you will need to close from Windows Task manager. If you are going to run Excel invisibly then ensure that you close the workbook and quit the Excel application when it is finished with. The following displays the workbook for testing purposes.

Code:
Sub Test()
Dim xlApp As Object, xlbook As Object, LastRow As Long

    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = True
    Set xlbook = xlApp.workbooks.Add
    xlbook.Sheets(1).Range("A1").PasteSpecial
    With xlbook.Sheets(1)
        If xlApp.WorksheetFunction.CountA(.Cells) <> 0 Then
            LastRow = xlbook.Sheets(1).Range("A" & xlbook.Sheets(1).Rows.Count).End(-4162).Row
        Else
            LastRow = 1
        End If
    End With
    MsgBox LastRow
End Sub

__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #2  
Old 05-24-2016, 04:28 AM
gbrew584 gbrew584 is offline worksheetfunction not working when controlling excel from word. Windows 7 64bit worksheetfunction not working when controlling excel from word. Office 2013
Novice
worksheetfunction not working when controlling excel from word.
 
Join Date: Apr 2015
Location: Ohio
Posts: 28
gbrew584 is on a distinguished road
Default

Thanks for the help and the great suggestions. I did as Paul suggested and tried to run the snipet of code by itself but it failed, that is what prompted my question about why it stopped working. I try to do my part and i always try people suggestions, run the code, make corrections, and then do tests before I come back and say something isn't working. I Appreciate that you are taking the time to help me as I am trying to lean more about writing code.

I will work on the code this afternoon to try and get the kinks worked out, thanks for your suggestions. I'll keep you posted on the progress. Thanks!!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word to Excel Links Stop Working DAC8190 Word 1 10-08-2015 05:56 PM
Controlling Widows (single-word lines at the end of a paragraph) downtownbooks Word 2 12-09-2014 03:57 PM
worksheetfunction not working when controlling excel from word. Word and Excel stopped working judyn Office 9 04-23-2013 05:10 AM
Controlling search option in word suvvi Word 0 08-05-2011 06:10 AM
worksheetfunction not working when controlling excel from word. working with excel tables in MS word radman154 Word Tables 1 03-25-2011 12:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:23 AM.


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