Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2022, 08:14 PM
getsubodh@gmail.com getsubodh@gmail.com is offline Open word document and copy Windows 11 Open word document and copy Office 2019
Novice
Open word document and copy
 
Join Date: Sep 2022
Posts: 1
getsubodh@gmail.com is on a distinguished road
Default Open word document and copy

Hi I am using the following code to open a word document


Sub Open_Word_Doc()
Dim intChoice As Integer
Dim strPath As String
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True

Application.FileDialog(msoFileDialogOpen).AllowMul tiSelect = False
intChoice = Application.FileDialog(msoFileDialogOpen).Show
'if the user selects a file
If intChoice <> 0 Then
'get the path selected
strPath = Application.FileDialog( _
msoFileDialogOpen).SelectedItems(1)
'opens the document
objWord.Documents.Open (strPath)

End If
End Sub

I am trying to amend it so that i can copy all the contents of the word document (like Ctrl + A ) and copy it.

How can i do that.

Thanks in advance.
Reply With Quote
  #2  
Old 09-13-2022, 01:34 AM
Guessed's Avatar
Guessed Guessed is offline Open word document and copy Windows 10 Open word document and copy Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You should name the document as a variable as you open it.
Code:
Dim oDoc as Object
Set oDoc = objWord.Documents.Open(strPath)
Then you can copy the document's range to the clipboard
Code:
oDoc.Range.Copy
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Charles Kenyon; 09-13-2022 at 05:00 AM.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Make Userform Copy From One Word Document to Another Marrick13 Word VBA 0 03-19-2018 10:45 AM
look for a specific word in document and copy it to the filename sylvio Word VBA 4 03-09-2017 05:53 PM
Adding tables to Created word document whilst other word document open Help rpb925 Word VBA 18 03-30-2016 04:45 PM
Word Document won't open neusys Office 0 09-16-2013 12:05 AM
Open word document and copy Copy from one word document to another no identical gmurphy Word 3 09-07-2011 04:28 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:40 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