none
I want to run a macro to open up a specific folder and let me INSERT the text of a word doc I select

    Question

  • I can get it to open the location I want. But my only option is to open the file I selected. I want to insert that text into the current doc.

    Sub OpenFolder()

    With Application.Dialogs(wdDialogFileOpen)
    .Name = "C:\Users\Ken\Quick Parts\RFP TOPICS"
    .Show
    End With
    End Sub

    Friday, March 09, 2018 2:25 AM

All replies

  • I can get it to open the location I want. But my only option is to open the file I selected. I want to insert that text into the current doc.

    Sub OpenFolder()

    With Application.Dialogs(wdDialogFileOpen)
    .Name = "C:\Users\Ken\Quick Parts\RFP TOPICS"
    .Show
    End With
    End Sub

    Well if you want to program in VB.Net then you would programmatically open a Microsoft Word Object I believe and programmatically insert text. However it looks to me like you are programming a Macro for MS Word or something else which this forum would not be for. If you want to ask questions in a VB Script forum then that forum is here JScript and Scripting possibly or maybe here The Official Scripting Guys Forum! or maybe somewhere else.

    Maybe this forum also Visual Basic for Applications (VBA).

    And please see this link VBScript and see the links for the user guide and language reference on the left side of the page.


    La vida loca

    Friday, March 09, 2018 2:37 AM
  • I can get it to open the location I want. But my only option is to open the file I selected. I want to insert that text into the current doc.

    Sub OpenFolder()

    With Application.Dialogs(wdDialogFileOpen)
    .Name = "C:\Users\Ken\Quick Parts\RFP TOPICS"
    .Show
    End With
    End Sub

    Hi tekwrite,

    If you want to write some text into selected word file in vb.net, you can take a look the following code:

    openFileDialog1.InitialDirectory = "D:\"
        openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
        openFileDialog1.FilterIndex = 2
        openFileDialog1.RestoreDirectory = True
        If openFileDialog1.ShowDialog() = DialogResult.OK Then
            Try
                Dim filename As String = openFileDialog1.FileName
                Dim app As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application()
                Dim doc As Microsoft.Office.Interop.Word.Document = app.Documents.Open(filename)
                Dim missing As Object = System.Reflection.Missing.Value
                doc.Content.Text += textBox1.Text
                app.Visible = True
                doc.Save()
                Me.Close()
            Catch ex As Exception
                MessageBox.Show("Error: Could not read file from disk. Original error: " & ex.Message)
            End Try
        End If

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 09, 2018 8:27 AM
    Moderator