Click here to Skip to main content
16,012,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi , i had created a new .doc file, in the coding part a single doc file is readed and writed to the new doc file ...

how can i continue the operation for reading multiple doc file and write it to a new doc file .....

VB
 Imports System.Windows.Forms
Imports word = Microsoft.Office.Interop.Word
Imports Microsoft.Office.Interop.Word
Imports System.Runtime.InteropServices

Public Class Form1
    Dim flb As New System.Windows.Forms.FolderBrowserDialog
    Dim fod As OpenFileDialog = New OpenFileDialog()
    Dim objapp As New word.Application
    Dim objdoc As New word.Document
    Dim object1 As Object
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        flb.RootFolder = Environment.SpecialFolder.MyComputer
        flb.ShowNewFolderButton = False
        Dim result As DialogResult = flb.ShowDialog
        If (result = DialogResult.OK) Then
            ListBox1.Items.Clear()
            TextBox1.Text = flb.SelectedPath
            For Each filename In Directory.GetFiles(flb.SelectedPath, "*.doc").Union(Directory.GetFiles(flb.SelectedPath, "*.rtf").ToArray())
                             
            Next
        End If
    End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
 Call readandwrite()

    End Sub
    Sub readandwrite()

        Dim missing As Object = System.Reflection.Missing.Value
        Dim oFals As Object = False
        Dim oTru As Object = True
        
        Dim obj1 As Object
        obj1 = TextBox1.Text & "\sam1"


         Try
        objapp = New word.Application
        objdoc = New word.Document

        If ListBox1.Items.Count > 0 Then

            For i As Integer = 0 To ListBox1.Items.Count - 1
                Dim obj As Object = ListBox1.Items(i)
                
                objdoc = objapp.Documents.Open(obj, missing, oTru, missing)
                objapp = New word.Application
                objdoc = New word.Document

                objdoc = objapp.Documents.Add(obj)
                
                objdoc.SaveAs(obj1)

              

                objdoc.Activate()
                objdoc.Close()
                objapp.Quit()


                objdoc = Nothing
                objapp = Nothing

            Next



        End If
        Catch ex As Exception
         MsgBox("read error")
         End Try

    End Sub
Posted
Updated 14-Nov-11 22:33pm
v2

1 solution

step 1 -> create a loop (foreach), which will iterate for number of files you have selected, in file open dialogue box (set property Multiselect = true).

2 -> write your file reading code inside this loop, use the filename from the iteration variable of your loop.

3-> write your new file creation and writing code below the reading code (inside the loop only)

4 -> end of loop.


follow the link to see the example

http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.multiselect.aspx[^]

mark as answer if helps you, it motivates :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900