Ok, so I want to make a program that creates a text file on the user's desktop, But I also want it to work on more than just my computer, Any ideas?
I see you've already accepted an answer from #Jonco98. However, there's no guarantee that C:\Users will always be the root user folder. On XP, it may be under Documents and Settings. Or, the OS may be installed on a drive letter other than C.
A better way to retrieve the user's desktop is by using the WshSpecialFolders collection.
strDesktopFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop")
Ok, so heres what I got:
Set File = CreateObject("Scripting.FileSystemObject")
Set User = CreateObject("Wscript.Network")
Set Report = File.CreateTextFile("C:\Users\" & User.UserName & "\Desktop\Report.txt", True)
And if you want to type in something to the file say the date and time add this after the first three lines:
Report.WriteLine(vbNewLine & "Accessed On: " & Day(date) & "/" & Month(date) & "/" & Year(date) & vbNewLine & "Accessed At: " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now))
Report.Close
Related
I want to use hammerspoon to find one specific chrome tab across al chrome windows across all spaces.
The only way I was able to achieve this was using osascript, which I don't like much because it means to use a big multi-line string inside Lua. I will prefer to use native hammerspoon methods with Lua.
Just in case, here is my version using osascript that works perfectly:
local function osa()
local tabName = "whatsapp"
local script = [[
tell application "Google Chrome" to activate
tell application "Google Chrome"
set found to false
repeat with theWindow in windows
repeat with theTab in (tabs of theWindow)
if the title of theTab contains "%s" then
set found to true
set index of theWindow to 1
return id of theTab
end if
end repeat
end repeat
return found
end tell
]]
local success, windowID, errors = hs.osascript.applescript(string.format(script, tabName))
print(success, windowID, type(windowID), hs.inspect(errors))
if success == false then
hs.alert.show("Tab with name '" .. tabName .. "' not found.")
else
hs.alert.show("Tab '" .. tabName .. "' found and brought to front.")
end
end
I have an Access form with the drawing number D-A1ER-1378-1601-0 listed which is also stored in a file folder.
I use the code below to open the pdf drawing, which works fine.
Public Sub OpenDWG()
Dim strFile As String
Dim PathPDF As String
On Error GoTo Failure
PathPDF = DLookup("[FilePath]", "[SettingsDrawingFilePathTbl]", "ID = 4")
strFile = PathPDF & "\" & Screen.ActiveControl & ".pdf"
If Len(Dir(strFile)) Then
FollowHyperlink strFile
Else
MsgBox "No Document found for this Drawing Number, check Engineering Drawing Search File path in the Settings Tab and / drawing download files"
End If
Exit Sub
Failure:
MsgBox Err.Description
Err.Clear
End Sub
How do I adjust the strfile name
strFile = PathPDF & "\" & Screen.ActiveControl & ".pdf"
to get the form to open only the most recent file when a new version of the drawing is dropped into the folder. ie D-A1ER-1378-1601-0(2) will be the newest revision.
I would like to add a comment, but I don't have enough points ot comment.
I think that you can use the Dir function to get all files beginning with the same characters, or with wild cards, etc. I'll have to look into how exactly to do this. You could populate an array with these, and use code to scan the array to determine the latest file. Or you could populate a temporary table amd then use the table contents as the course to a combo box to have the user select the desired file, sorted with the latest one on top.
If I get a chance, I'll conjure up some sample code an post it.
I'm working on a homework reminder app. I recently asked a question concerning using "write" properly and had my question answered. My script was working perfectly, but now it has stopped writing anything to my file. I must have changed something, but I can't figure out what's wrong. Any suggestions?
(Please Note: This is still a work-in-progress and not everything is competed; however the part using "write" should not be effected)
Code:
set saveFile to (path to desktop as text) & "Script Log.txt"
set assignments to read file the saveFile from 1 to eof using delimiter "*"
repeat
display dialog "What would you like to do?" buttons {"New Assignment", "Delete/Edit Assignment", "Exit"}
set function to button returned of result
if function = "New Assignment" then
display dialog "What subject is this assignment for?" default answer ""
set subject to text returned of result
display dialog "What do you need to bring home for this assignment?" default answer ""
set materials to text returned of result
display dialog "What is the assignment?" default answer ""
set instructions to text returned of result
(choose from list {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Long-Term"} with prompt "When is this assignment due?")
set dueDate to result as text
if dueDate = "Long-Term" then
display dialog "When is this due?" default answer ""
set dueDat to text returned of result
end if
set assignments to {assignments & (subject & ": You need to bring " & materials & " home. It is due on " & dueDate & ". For this assignment, you need to " & instructions & ".")}
else if function = "Delete/Edit Assignment" then
(choose from list {item 1 of assignments} with prompt "Which assignmnet would you like to delete/edit?")
else if function = "Exit" then
set fullText to ""
repeat with i from 1 to number of items in assignments
set thisItem to item i of assignments & "*"
set fullText to fullText & thisItem
if i is not number of items in assignments then set fullText to fullText & return
end repeat
my scriptLog(fullText)
exit repeat
end if
end repeat
on scriptLog(thisText)
try
open for access file the saveFile with write permission
write (thisText & return) to file the saveFile starting at eof
close access file the saveFile
on error
try
close access file the saveFile
end try
end try
end scriptLog
display dialog assignments
The saveFile is not defined inside the scriptLog handler.
Change the top line : set saveFile to (path to desktop as text) & "Script Log.txt"
to a property, since it value is static. A property is automaticly global to the rest of the code and it's handlers.
property saveFile : (path to desktop as text) & "Script Log.txt"
The other thing to remember is that try blocks can hide any errors when you are debugging so you should remember to comment them out if you are debugging.
I am using VB.Net and EWS Managed API to create appointments in Exchange 2010. When i call the "Save" method, an appointment is not created on the first machine but when i use the same Code on the second machine it works!
Thanks.
I use below code to save an appointment in the Outlook Calendar:
appointment.RequiredAttendees.Add(myKalender)
appointment.IsReminderSet = False
Try
System.Net.ServicePointManager.ServerCertificateValidationCallback = _
Function(se As Object, _
cert As System.Security.Cryptography.X509Certificates.X509Certificate, _
chain As System.Security.Cryptography.X509Certificates.X509Chain, _
sslerror As System.Net.Security.SslPolicyErrors) True
appointment.Save(SendInvitationsMode.SendToNone)
Console.Write("erfolgreich Eingetragen " & Now)
Catch
Console.Write("Fehler beim Erstellen des Termins " & Now & " " & Err.Description)
End Try
I need to version control a Microsoft Access 2007 database and application. Currently everything is contained in a single mdb file.
The application includes:
Forms
VBA code
Actual database
I would assume I need to separate the database from the forms/code. I would like to be able to version control the forms/code as text to support version diffs.
At the moment I don't have access to SourceSafe (I heard there may be some access support) so I would prefer a solution that would work with subversion or git.
Access 2007 has a feature where you can split a DB into its Tables/Queries (backend) and Forms/Reports (front-end). Since your question mentions only version controlling the forms and modules, this might be a more elegant solution. I don't know where modules go after the split, so that might be a stumbling block.
Microsoft offers VSTO (Visual Studio Tools for Office), which will let you develop in VS and run version control via any VS plugin (CVS/SVN/VSS/etc.).
Finally, you can just directly connect to Visual Source Safe. This MSKB article has some good information and background to go through, while this Office Online article is designed for getting you up and running.
Ultimately, I would suggest against taking the code out of Access if at all possible. Assuming the VBA editor is your primary development environment, you'll be adding extra steps to your development process that cannot easily be automated. Every change you make will need to be manually exported, diff'd, and stored, and there is no Application.OnCompile event that you could use to export the changes. Even tougher, you'll have to manually import all changed source files from other developers when they do checkins.
I use the code below to extract the vba code from Excel files, you may be able to modify this to extract from Access.
Sub ExtractVBACode(strSource, objFSO, strExportPath, objLogFile)
Dim objExcel
Dim objWorkbook
Dim objVBComponent
Dim strFileSuffix
Dim strExportFolder
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = true
Set objWorkbook = objExcel.Workbooks.Open(Trim(strSource))
strExportFolder = strExportPath & objFSO.GetBaseName(objWorkbook.Name)
If Not objFSO.FolderExists(strExportFolder) Then
objFSO.CreateFolder(strExportFolder)
End If
For Each objVBComponent In objWorkbook.VBProject.VBComponents
Select Case objVBComponent.Type
Case vbext_ct_ClassModule, vbext_ct_Document
strFileSuffix = ".cls"
Case vbext_ct_MSForm
strFileSuffix = ".frm"
Case vbext_ct_StdModule
strFileSuffix = ".bas"
Case Else
strFileSuffix = ""
End Select
If strFileSuffix <> "" Then
On Error Resume Next
Err.Clear
objVBComponent.Export strExportFolder & "\" & objVBComponent.Name & strFileSuffix
If Err.Number <> 0 Then
objLogFile.WriteLine ("Failed to export " & strExportFolder & "\" & objVBComponent.Name & strFileSuffix)
Else
objLogFile.WriteLine ("Export Successful: " & strExportFolder & "\" & objVBComponent.Name & strFileSuffix)
End If
On Error Goto 0
End If
Next
objExcel.DisplayAlerts = False
objExcel.Quit
End Sub
Can you extract the forms as XML perhaps?
I've struggled with this same problem. I originally wrote code very much like the existing answer. The trick is to get all of your modules onto the file system, but that method has some drawbacks. Going that route, you can get your forms and reports out of the VBA Projects, but you can't get them back in. So, I created a library as part of our Rubberduck VBE Add-in. The library I wrote takes care of importing and exporting all of your code to/from the VBA project to/from the repository as you seemlessly push, pull, and commit. It's a free and open source project, so feel free to download and install the latest version.
Here is an example of how the library is used. I'll be adding actual integration with the VBA editor in a future release.
Dim factory As New Rubberduck.SourceControlClassFactory
Dim repo As Rubberduck.IRepository
Dim git As ISourceControlProvider
Dim xl As New Excel.Application
xl.Visible = true
Dim wb As Excel.Workbook
Set wb = xl.Workbooks.Open("C:\Path\to\workbook.xlsm")
' create class instances to work with
Set repo = factory.CreateRepository(wb.VBProject.Name, "C:\Path\to\local\repository\SourceControlTest", "https://github.com/ckuhn203/SourceControlTest.git")
Set git = factory.CreateGitProvider(wb.VBProject, repo, "userName", "passWord")
' Create new branch to modify.
git.CreateBranch "NewBranchName"
' It is automatically checked out.
Debug.Print "Current Branch: " & git.CurrentBranch
' add a new standard (.bas) code module and a comment to that file
wb.VBProject.VBComponents.Add(vbext_ct_StdModule).CodeModule.AddFromString "' Hello There"
' add any new files to tracking
Dim fileStat As Rubberduck.FileStatusEntry
For Each fileStat In git.Status
' fileStat.FileStatus is a bitwise enumeration, so we use bitwise AND to test for equality here
If fileStat.FileStatus And Rubberduck.FileStatus.Added Then
git.AddFile fileStat.FilePath
End If
Next
git.Commit "commit all modified files"
' Revert the last commit, throwing away the changes we just made.
git.Revert