• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need help in VBA for embedded object in excel

HeenaS

New Member
Hi there,

I need help to write macro code to read & save the embedded text object to the path of activeworkbook. This is my code so far but still not getting desired output. any help is appreciated.

Code:
Dim FSO As Object
    Dim oEmbFile As OLEObject
    Dim Filename As String
    Dim NewPath As String
   
    Set oEmbFile = ThisWorkbook.Sheets("Sheet2").OLEObjects(1)
    'oEmbFile.Visible = False
    'NewPath = ActiveWorkbook.Path ' New directory name
    'MkDir NewPath
    'oEmbFile.Copy
    If Dir(ActiveWorkbook.Path & "\BCG_update.txt") <> "" Then
    oEmbFile.Copy
    'oEmbFile.savetofile ActiveWorkbook.Path & "\BCG_update.txt"
   
   
   
   
   
   
    CreateObject("Shell.Application").Namespace(ActiveWorkbook.Path & "\").Self.InvokeVerb "Paste"
    'oEmbFile.Object.SaveAs Filename:=NewPath & "\" & "BCG_update" & ".txt", FileFormat:=xlTextWindows
        If Dir(ActiveWorkbook.Path & "\BCG_update.txt") <> "" Then
            Set FSO = CreateObject("scripting.filesystemobject")
                If Dir("C:\BCGexpanderLib\") = "" Then
                 MkDir ("C:\BCGexpanderLib")
                End If
                    If Dir("C:\BCGexpanderLib\Dll1.dll") <> "" Then
                        FSO.Deletefile "C:\BCGexpanderLib\Dll1.dll"
                    End If
       FSO.moveFile ActiveWorkbook.Path & "\BCG_update.txt", "C:\BCGexpanderLib\Dll1.dll"
    Else
   
    'oEmbFile.Object.SaveAs2 Filename:=NewPath & "\" & "BCG_update" & ".txt", FileFormat:=xlTextWindows
Application.DisplayAlerts = True


    End If
    If Dir("C:\BCGexpanderLib\") = "" Then ' need to update this to check for valid updates to dll
       MsgBox "BCG_update.txt not found"
       End
    End If
 
Last edited by a moderator:
I'd recommend uploading sample workbook with embedded object, and also sample of your desired output (created manually if needed).

Otherwise, we have no idea what your expected output should look like.

FYI - Took a quick glance at your code. You have Dll1.dll as export... but you can't simply rename text file to dll file. It must be compiled.
 
its just a simple text file (BCG_update.txt) embedded in macro enabled worksheet which I wish to read by Macro and save the text file at the same path of excel.
This dll file has other significant and may not get affected. This dll file has reference to read the file at activeworkbook path and perform the next operation.
 
I'd recommend uploading sample workbook with embedded object, and also sample of your desired output (created manually if needed).

Otherwise, we have no idea what your expected output should look like.

FYI - Took a quick glance at your code. You have Dll1.dll as export... but you can't simply rename text file to dll file. It must be compiled.
yes, the last part containing Dll is runing fine...I need urgent help on saving text ole file to activeworkbook path.. pls help
 
Back
Top