How to load the .docx to word doc, also make me to understand the code(black magic)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: How to load the .docx to word doc, also make me to understand the code(black magic)

Threaded View

  1. #1
    Join Date
    Jan 2013
    Posts
    23

    How to load the .docx to word doc, also make me to understand the code(black magic)

    Hi All,

    I want some help from you people, please help me.

    I have created a new program, in which i have added the below code from another program which is written by other person, who has left the job….. I am not at all able understand this piece of code… also the person has written it as BLACK Magic for that code above u cn find it below..



    But this code is loading the selected .docx file ….. How its doing, can any one plz plz plz help me…

    Code:
    Imports Microsoft.Office.Interop.Word 
    Imports Microsoft.Office.Interop.Excel 
      
    Imports Microsoft.Office.Interop 
      
    Public Class Word_doc_Export 
        Private WithEvents oWord As Word.Application 
        Private WithEvents oDoc As Word.Document 
        Dim Loading As Boolean 
        Dim ExperimentMode As String '"WordActivateMode" or "FakeHighlightMode" 
        Const FakeHighlightMode = "FakeHighlightMode" 
        Const WordActivateMode = "WordActivateMode" 
        Dim PreviousHighlightColorIndex As Word.WdColorIndex 
        Dim WorkingSourceFileName As String = "" 
        Public FileName As String 
        Dim WordHandle As Integer 
      
        Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer 
        Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer 
        Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer 
        Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Integer) As Integer 
      
        Dim WordVersion As String 
      
        Private Sub Word_doc_Export_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
            oWord = New Word.Application 
            WorkingSourceFileName = " C:\Users\aseema\Desktop\zzz.docx" 
        End Sub 
      
        Private Sub frmRA2_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated 
      
            If Not Loading Then 
                If Not oWord Is Nothing Then 
                    Try 
                        If oWord.Selection.Range.HighlightColorIndex = Word.WdColorIndex.wdNoHighlight Then 
                            If ExperimentMode = FakeHighlightMode Then 
                                oWord.Selection.Range.HighlightColorIndex = Word.WdColorIndex.wdGray25 
                            End If 
                        End If 
                    Catch ex As Exception 
                    End Try 
                End If 
            End If 
      
        End Sub 
      
        Private Sub frmRA2_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate 
      
            If Not Loading Then 
                If Not oWord Is Nothing Then 
                    If ExperimentMode = FakeHighlightMode Then 
                        If oWord.Selection.Range.HighlightColorIndex = Word.WdColorIndex.wdGray25 Then 
                            'oWord.Selection.Range.HighlightColorIndex = Word.WdColorIndex.wdNoHighlight 
                            If PreviousHighlightColorIndex <> 9999999 Then 
                                oWord.Selection.Range.HighlightColorIndex = PreviousHighlightColorIndex 
                            End If 
                        End If 
                    End If 
                End If 
            End If 
      
        End Sub 
      
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
            Dim sv As New FarPoint.Win.Spread.SheetView 
            Dim i As Integer 
            Dim j As Integer 
            Dim k As Integer 
            Dim sTemp As String 
            Dim chkbox As New FarPoint.Win.Spread.CellType.CheckBoxCellType 
            Dim iParent As Integer 
            Dim FileNameWithoutPath As String 
            Dim ServiceCategoryName As String 
      
             
            Loading = True 
      
            FileNameWithoutPath = System.IO.Path.GetFileName(FileName) 
      
            grd.Visible = False 
            Panel1.Dock = DockStyle.Fill 
            pnlWordContainer.Dock = DockStyle.Fill 
            pnlWordContainer.Visible = False 
      
      
            '****************************************************** 
            'Black Magic 
            '****************************************************** 
            oWord = New Word.Application 
      
            oWord.Caption = "SIM" 
            WordHandle = FindWindow("Opusapp", "SIM") 
            SetParent(WordHandle, Me.pnlWordContainer.Handle.ToInt32) 
            oWord.Caption = Nothing 
            My.Application.DoEvents() 
      
             
            oDoc = oWord.Documents.Open(FileName, False) 
            'FileOpen(1, FileName, OpenMode.Append, OpenAccess.Default, OpenShare.Default, -1) 
      
            oDoc.Application.Visible = True 
            oDoc.Application.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone 
      
            oWord.Options.WarnBeforeSavingPrintingSendingMarkup = False 
      
            My.Application.DoEvents() 
      
            ' ResizeWordWindow() 
            '****************************************************** 
       
        End Sub 
       
      
        End Function 
      
    End Class
    Will be waiting for your reply…

    Kind Regards
    Seema
    Last edited by SeemsP; January 30th, 2014 at 06:31 AM. Reason: title edit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center