Results 1 to 2 of 2

Run vbs file and copy folder name into excel

Threaded View

  1. #1
    Registered User
    Join Date
    12-30-2020
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    16

    Run vbs file and copy folder name into excel

    Hi all,

    I have a .vbs file which opens an existing excel macro file and run specified macro.

    Then, Excel macro will open an existing word document and replaces few strings on that file.
    I need to update the current folder name (where the .vbs file located) into the word document through excel macro.

    With the following code I can able to update the current excel file location. However, I need the file path and folder name where we copied & run the .vbs file .
    .Replacement.Text = Mid(ActiveDocument.Path, InStrRev(ActiveDocument.Path, "") + 1)
    Here is the source code (.vbs file) to open excel and run macro:
    Set objExcel = CreateObject("Excel.Application")
    objExcel.Application.Run "'C:\Users\SS\Downloads\Test Temp\FIN Tool_1.xlsm'!Module1.Test22"
    objExcel.DisplayAlerts = False
    objExcel.Application.Quit
    Set objExcel = Nothing


    VBA MACRO source code to open word document and replace strings:
    Sub Test22()
    
    Dim book1 As Word.Application
    Dim sheet1 As Word.Document
    Dim scriptpath As String
    Set book1 = CreateObject("word.application")
    book1.Visible = True
    Set sheet1 = book1.Documents.Open("C:\Users\Sailaja Srinivas\Downloads\Test Temp\FIN_Template.docx")
    
    With sheet1.Content.Find
    
            .Text = "USERNAME"
            .Replacement.Text = "SRINIVAS PONNADA"
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchCase = False
            .Execute Replace:=wdReplaceAll
    End With
    
    With sheet1.Content.Find
    
            .Text = "CURRENT FILE FOLDER"
            .Replacement.Text = Mid(ActiveDocument.Path, InStrRev(ActiveDocument.Path, "") + 1)
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchCase = False
            .Execute Replace:=wdReplaceAll
    End With
    End Sub
    Last edited by savinirsb4u; 06-03-2023 at 09:31 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy File names from Folder / Sub Folders to Excel
    By fitkhan in forum Excel General
    Replies: 10
    Last Post: 06-07-2021, 09:17 AM
  2. Replies: 0
    Last Post: 09-16-2020, 04:42 AM
  3. copy file from excel list to other folder
    By mattmar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2020, 04:18 PM
  4. copy file from excel list with extension to other folder
    By mattmar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2020, 01:36 PM
  5. Replies: 18
    Last Post: 02-18-2019, 07:42 AM
  6. [SOLVED] Copy folder names to Excel File
    By fitkhan in forum Excel General
    Replies: 2
    Last Post: 09-19-2014, 11:54 AM
  7. Replies: 0
    Last Post: 01-21-2014, 10:52 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1