0

From within MS Excel I have VBA code which runs VBA code within MS Word. Everything works fine. I need to return a string value from Word, back into an Excel variable. Is this possible?

Some irrelevant background... I'm building a list of pdf files within Excel and need to extract values out of each of those pdf files. Word natively reads pdf, that's why I'm using it. I have a perfectly working python script that does it but no-one else in the organisation knows python and my manager isn't comfortable having code that only I understand. Which is fair enough!

Any hint would be appreciated!

3
  • 2
    Please edit your question with your code. Commented Mar 27, 2020 at 16:06
  • You can use clipboard. Copy in Word macro and then paste in Excel from clipboard Commented Mar 27, 2020 at 16:25
  • Clipboard! Of course! Doh! Thanks a million! Commented Mar 29, 2020 at 11:09

1 Answer 1

1

Excel:

Sub RunWord()

    Dim appWd As Object, res

    Set appWd = GetObject(, "Word.Application")

    res = appWd.Run("Tester")

    Debug.Print res

End Sub

Word:

Public Function Tester()
    Tester = "hi!"
End Function
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.