Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

John Miller

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

VBA DDE WORD EXCEL

// This is just sample code of some dde commands

Sub RUNEXCELMACRO()
'RUN MACRO
aChan = DDEInitiate(App:="Excel", Topic:="System")
DDEExecute Channel:=aChan, Command:="[Run(" & Chr(34) & _
    "Personal.xls!Macro1" & Chr(34) & ")]"
DDETerminate Channel:=aChan
'POKE
Chan = DDEInitiate(App:="Excel", Topic:="System")
DDEExecute Channel:=Chan, Command:="[OPEN(" & Chr(34) _
    & "C:\Sales.xls" & Chr(34) & ")]"
DDETerminate Channel:=Chan
Chan = DDEInitiate(App:="Excel", Topic:="Sales.xls")
DDEPoke Channel:=Chan, Item:="R1C1", Data:="1996 Sales"
DDETerminate Channel:=Chan
'This example opens the Microsoft Excel workbook Book1.xls and retrieves the contents of cell R1C1.
Chan = DDEInitiate(App:="Excel", Topic:="System")
DDEExecute Channel:=Chan, Command:="[OPEN(" & Chr(34) _
    & "C:\My Documents\Book1.xls" & Chr(34) & ")]"
DDETerminate Channel:=Chan
Chan = DDEInitiate(App:="Excel", Topic:="C:\DATA\SBS.xls")
msg = DDERequest(Channel:=Chan, Item:="R2C1")
msg = msg & " " & DDERequest(Channel:=Chan, Item:="R2C2")
MsgBox msg
DDETerminateAll
'This example opens a channel to the System topic in Microsoft Excel and then uses the Topics item to return a list of available topics. The example inserts the topic list, which includes all open workbooks, after the selection.
aChan = DDEInitiate(App:="Excel", Topic:="System")
TOPICLIST = DDERequest(Channel:=aChan, Item:="Topics")
Selection.InsertAfter TOPICLIST
DDETerminate Channel:=aChan

End Sub

File System Object VBScript

vbscript class wrapper to expose file system object methods and properties.

CLASS FSOBJ
dim FSO, f, f1, fc, s
dim  nso
Sub Class_Initialize()
   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set nso = CreateObject("WScript.Network")
End Sub

Sub Class_Terminate()
   Set FSO = Nothing
   Set nso = Nothing
End Sub
Property Get GetFolder(folderspec) 
Set GetFolder = FSO.GetFolder(folderspec)
End Property
Property Get GetFile(filespec)
Set GetFile = FSO.GetFile(filespec)
End Property
Property Get GetFileSize(filespec) 

Set f = FSO.GetFile(filespec)
GetFileSize = f.Size
End Property
Property Get GetComputerName() 
 GetComputerName = nso.computername
End Property

Function FolderExists(folderspec)
   Set FSO = CreateObject("Scripting.FileSystemObject")
   FolderExists = FSO.FolderExists(folderspec)
End Function
Function FileExists(pathNfilespec)
    'folderspec = Left(pathNfilespec, Len(pathNfilespec) - InStrRev(pathNfilespec, "\") + 1)
    'filespec = Right(pathNfilespec, InStrRev(pathNfilespec, "\") - 1)
   Set FSO = CreateObject("Scripting.FileSystemObject")
   'FolderExists = fso.FolderExists(folderspec)
   FileExists = FSO.FileExists(pathNfilespec)
End Function
Function FileDelete(pathNfilespec)
    'folderspec = Left(pathNfilespec, Len(pathNfilespec) - InStrRev(pathNfilespec, "\") + 1)
    'filespec = Right(pathNfilespec, InStrRev(pathNfilespec, "\") - 1)
   Set FSO = CreateObject("Scripting.FileSystemObject")
   If FSO.FileExists(pathNfilespec) = True Then
   FSO.DeleteFile pathNfilespec, True
   End If
End Function
Function ShowFileAccessInfo(filespec)
  Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(folderspec) = True Then
    Set f = FSO.GetFile(filespec)
  s = f.path & "<br>"
  s = s & "Created: " & f.DateCreated & "<br>"
  s = s & "Last Accessed: " & f.DateLastAccessed & "<br>"
  s = s & "Last Modified: " & f.DateLastModified
  ShowFileAccessInfo = s
End If
End Function
Function FileModified(pathNfilespec)
    'folderspec = Left(pathNfilespec, Len(pathNfilespec) - InStrRev(pathNfilespec, "\") + 1)
    'filespec = Right(pathNfilespec, InStrRev(pathNfilespec, "\") - 1)
   Set FSO = CreateObject("Scripting.FileSystemObject")
     Set f = FSO.GetFile(pathNfilespec)
   If FSO.FileExists(pathNfilespec) = True Then
   FileModified = f.DateLastModified
   End If
End Function
Function FileAccessed(pathNfilespec)
    'folderspec = Left(pathNfilespec, Len(pathNfilespec) - InStrRev(pathNfilespec, "\") + 1)
    'filespec = Right(pathNfilespec, InStrRev(pathNfilespec, "\") - 1)
   Set FSO = CreateObject("Scripting.FileSystemObject")
     Set f = FSO.GetFile(pathNfilespec)
   If FSO.FileExists(pathNfilespec) = True Then
   FileAccessed = f.DateLastAccessed
   End If
End Function
Sub AddNewFolder(path, folderName)
Dim nf
   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set f = FSO.GetFolder(path)
   Set fc = f.SubFolders
   If folderName <> "" Then
      Set nf = fc.Add(folderName)
   Else
      Set nf = fc.Add("New Folder")
   End If
End Sub


Function ShowFileList(folderspec)

   Dim FSO, f, f1, fc, s

   Set FSO = CreateObject("Scripting.FileSystemObject")

   Set f = FSO.GetFolder(folderspec)

   Set fc = f.FILES

   For Each f1 In fc

      s = s & f1.Name

      s = s & vbTab

   Next

   ShowFileList = s

End Function
Sub FILES(FolderNPath)

   Dim FSO, f, f1, fc, s

   Set FSO = CreateObject("Scripting.FileSystemObject")

   Set f = FSO.GetFolder(FolderNPath)

   Set fc = f.FILES

   For Each f1 In fc
    
   Next
End Sub
Sub CopyFile(Source , Destination , Overwrite )
    
FSO.CopyFile Source, Destination, Overwrite
End Sub

END CLASS
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS