I am a beginner in JScript , i did a program to remove a file from folder to another in JScript , but each time i need to change those path if i gave it to another person it depends on their path in their computer. So they ask me to do a txt file which they change only the informations below and then the JScript will change either .
enter code here
the JScript :
MoveFile2Desktop(filespec)
{var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.MoveFile(filespec, "c:\\windows\\desktop\\");
}
and i have a .txt file which contains
Source: P:\Desktop\name.txt
Destination : P:\Desktop\Folder1\name.txt
How can i read these 2 information and replace it in a JScript ?
Related
I want to edit a pdf file attached as an object to my Excel doc with VBA.
Background: Since I don't want to share both files in a .zip or else and there is no network drive everybody has granted access to, I need a "foolproof" solution.
The pdf file contains a form (mandatory) and will be filled with information from this Excel doc. As mentioned, I already had a solution with the pdf file stored on a network drive.
Dim file, new_name As String
Set AcroApp = CreateObject("AcroExch.App")
Set AvDoc = CreateObject("AcroExch.AVDoc")
'Open new PDF file
'Use local path
file = "C:\Users\992\Desktop\example.pdf"
new_name = "New_PDF_12092019"
If AvDoc.Open(Datei, Name) Then
AcroApp.Show
Set PDDoc = AvDoc.GetPDDoc()
Set jso = PDDoc.GetJSObject
'Get cart ID
jso.getField("Feld1").Value = CStr(ActiveSheet.Range("B12").Value)
'Get Project ID
jso.getField("Feld2").Value = CStr(ActiveSheet.Range("B14").Value)
...
My question is: is there any possibility to use an embedded object with AcroExch.AVDoc?
Since parameter szFullPath requires the full path of the file to open, I thought about getting the "path" of the object and use it - but I cannot figure out how. Already tried this: https://danny.fyi/embedding-and-accessing-a-file-in-excel-with-vba-and-ole-objects-4d4e7863cfff
Maybe someone can help me with this.
Thanks in advance!
so i searched but didnt find something good for my use , i have a folder where i will import an excel file , this excel file will have a different name everytime how i can open it with vba , thank you
You can get the file name using the Dir function and multiple character (*) wildcard.
Const Path As String = "C:\Test"
Dim filename As String
filename = Dir(Path & "\*.xlsx")
If Len(filename) > 0 Then
' Do your work
' Remember 'filename' only holds the file name
' you will need to attach the rest of the path to get the full directory.
End If
Note: If there's only one file in the folder you will not have any issues, however if the folder contains multiple files (matching the above pattern), you will need to either loop or provide additional file name characters to the function.
An example:
File name: daily_report_20190404.xlsx
filename = Dir(Path & "\daily_report_*.xlsx")
Hope this helps.
I am creating a macro in Excel that should open a PDF document on a specified page with chrome.
Generally, the opening part works. My problem is that when I add the page number (e.g. #page=15) to the url, the shell encodes the "#" symbol into "%23", which Chrome is not able to interpret correctly (file not found).
Here is my code
'The path to the file, replaces spaces with the encoding "%20"
Path = Replace((filePath& "#Page=" & iPageNum), " ", "%20")
Dim wshShell, chromePath As String, shellPath As String
Set wshShell = CreateObject("WScript.Shell")
chromePath = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe\")
shellPath = CStr(chromePath) & " -url " & Path
If Not chromePath = "" Then
'how I first tried it:
Shell (shellPath)
'for testing purposes, led to the same result though:
Shell ("""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" ""C:\Users\t.weinmuellner\Desktop\Evon\PDF Opening\PDFDocument.pdf#page=17""")
End If
Is there a different way to do this with Chrome? I haven't found anything that reads the installation path dynamically.
You just need to specify the protocol file:/// if you want to load files from the local hard disk. Then # gets not translated into %23.
Shell ("""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" ""file:///C:\Users\t.weinmuellner\Desktop\Evon\PDF Opening\PDFDocument.pdf#page=17""")
If Adobe Acrobat Reader is installed on the system I would suggest to use the funcion openPDF from Daniel Pineault. This will open the file in Adobe Reader directly. You can find the source code of the function here
A test could look like that
Sub TestSO()
Dim fileName As String
Dim pageNo As Long
fileName = "Path and filename of PDF"
pageNo = 20
OpenPDF fileName, 20
End Sub
I try to write script on Google Sheet to trigger below action.
Move a target file from root (my drive) to the destination folder then rename it in the destination folder.
Below items will be put on google sheet . I want to create a formula function to trigger the script action once below items are provide on google sheet.
Target file name
Name ID for rename
Below script works perfectly (for move file action); i would like alter below script to accomplish above action.
function copyFiles(source_folder, dest_folder) {
var source_folder = DriveApp.getFolderById(id);
var dest_folder = DriveApp.getFolderById(id);
var files = DriveApp.getFilesByName(id);
while (files.hasNext()) {
var file = files.next();
dest_folder.addFile(file);
source_folder.removeFile(file);
}
}
Thank you!!
If you just want to rename your file, you should have a look at File classe, on File.setName(name) method.
Otherwise, you question is a bit unclear and need some explanations/examples of what you trying to do.
I have a dll that needs to open an excel file but i cannot seem to create the path to the file. The excel file is a template that must be used to compare with an excel file that the user will browse for and open.
I have used this code previously when using an exe file for my application:
string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Data\\BulkMaintenanceExample.xls");
but with a dll it does not seem to work. Any Ideas?
Try following to get the assembly path:
var dir = AppDomain.CurrentDomain.BaseDirectory;
or
//get the full location of the assembly with DaoTests in it
string fullPath = System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location;
string theDirectory = Path.GetDirectoryName( fullPath );
or
string filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
return Path.GetDirectoryName(filePath);