NOT ABLE TO OPEN WORD FILE

deepak30

New Member
Joined
May 11, 2020
Messages
41
Office Version
  1. 2013
  2. 2007
Platform
  1. Windows
Sir,
Below is my code I want to open file who's path with file name is mention in my sheet "PATH" in "COLUMN c6 ".
I can open file by giving hard cording of file name such as "C:\export\export.docx" but I do not want filenam or filepath to be fixed. so whatever path with file name is given in cell C6 it should open that file only
can anyone help me

VBA Code:
Sub WordToExcel()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Worksheets("pdfexcel").Activate
Range("A11:z10000").Clear
Dim Wdapp As Object, wddoc As Object
Dim LastRow As Long
Dim ExportFile As String
With Sheet1
    If ThisWorkbook.Sheets("path").Range("c9").Value = Empty Then
        MsgBox "Please Select your PDF File"
        GetSelectedPathAndConvert
    End If
    ExportFile = .Range("c9").Value
End With

Dim rng As Range
Dim i As Integer
On Error Resume Next
Set Wdapp = GetObject(, "word application")
If Err.Number = 429 Then
Err.Clear
Set Wdapp = CreateObject("word.application")
End If
Wdapp.Visible = True
Wdapp.Activate
Set wddoc = Wdapp.Documents(ExportFile)

If wddoc Is Nothing Then
    Set wddoc = Wdapp.Documents.Open(ExportFile)
    wddoc.Activate
End If
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Your code is looking at C9 not C6, and on the sheet whose codename is Sheet1 - is that the correct one?
 
Upvote 0
Your code is looking at C9 not C6, and on the sheet whose codename is Sheet1 - is that the correct one?


Sorry for mistakes I am re-posting my problem and macro

Below is my code I want to open file who's path with file name is mention in my sheet "PATH" in "COLUMN c9 ".
I can open file by giving hard cording of file name such as "C:\export\export.docx" but I do not want filename or filepath to be fixed. so whatever path with file name is given in cell C6 it should open that file only . My sheet name is where path is mention in column c9 is Sheet1


VBA Code:
Sub WordToExcel()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Worksheets("pdfexcel").Activate
Range("A11:z10000").Clear

''' extract data from word to excel
Dim Wdapp As Object, wddoc As Object
Dim LastRow As Long
'Dim FileName As String
Dim ExportFile As String
With Sheet1
    If ThisWorkbook.Sheets("path").Range("c9").Value = Empty Then
        MsgBox "Please Select your PDF File"
        GetSelectedPathAndConvert
    End If
    ExportFile = .Range("c9").Value
End With

Dim rng As Range
Dim i As Integer
On Error Resume Next
Set Wdapp = GetObject(, "word application")
If Err.Number = 429 Then
Err.Clear
Set Wdapp = CreateObject("word.application")
End If
Wdapp.Visible = True
Wdapp.Activate
Set wddoc = Wdapp.Documents(ExportFile)

If wddoc Is Nothing Then
    Set wddoc = Wdapp.Documents.Open(ExportFile)
    wddoc.Activate
End If
 
Upvote 0
Below is my code I want to open file who's path with file name is mention in my sheet "PATH" in "COLUMN c9 ".
I can open file by giving hard cording of file name such as "C:\export\export.docx" but I do not want filename or filepath to be fixed. so whatever path with file name is given in cell C9 it should open that file only . My sheet name is where path is mention in column c9 is Sheet1
 
Upvote 0
Sorry to everyone its was my mistake just like its difficult to find a needle in hay , it just happen with me i was opening file in vba "????.DOCX" but by actual file name was "?????.DOC" due to which i was not able to open
 
Upvote 0

Forum statistics

Threads
1,215,651
Messages
6,126,025
Members
449,281
Latest member
redwine77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top