Powershell script for setting Multi User Editing in excel for numerous files?
up vote
0
down vote
favorite
I've written a code that tries to go through my company server and set all the excel files, under a certain folder, to shared so that multiple people can edit them at once. This has been a problem for a very long time here and I thought I had a nice code to fix this but I can't seem to access the property correctly. Can anyone help?
$ErrorActionPreference = "Stop"
$root = "P:A N G"
$excelFiles = Get-ChildItem -path $root -File "*.xlsx" -Recurse
foreach ($excelFile in $excelFiles.FullName)
{
$excel = New-Object -ComObject Excel.Application
$excelWorkBook = $excel.Workbooks.Open($excelFile)
if (!$excelWorkBook.MultiUserEditing)
{
Write-Host $excelFile
$excelWorkBook._SaveAs([Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlShared)
$excelWorkBook.Close
}
}
excel powershell
|
show 3 more comments
up vote
0
down vote
favorite
I've written a code that tries to go through my company server and set all the excel files, under a certain folder, to shared so that multiple people can edit them at once. This has been a problem for a very long time here and I thought I had a nice code to fix this but I can't seem to access the property correctly. Can anyone help?
$ErrorActionPreference = "Stop"
$root = "P:A N G"
$excelFiles = Get-ChildItem -path $root -File "*.xlsx" -Recurse
foreach ($excelFile in $excelFiles.FullName)
{
$excel = New-Object -ComObject Excel.Application
$excelWorkBook = $excel.Workbooks.Open($excelFile)
if (!$excelWorkBook.MultiUserEditing)
{
Write-Host $excelFile
$excelWorkBook._SaveAs([Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlShared)
$excelWorkBook.Close
}
}
excel powershell
Is that accelerated .NET method,xlShared
, just a boolean? Also, after you callClose()
, most PS/Excel code I've seen calls.Quit()
after that as well. Are you able to open those Excel files from your machine? Or can you query the property on one of those Excel objects that you're trying to change after the code runs?
– trebleCode
Nov 21 at 20:06
@trebleCode For future reference, type accelerators are a specific class in the powershell library which essentially aliases types and the term does not apply to every use of a .NET type (which is what is happening here). Observe here:[psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get
It's likely an enumeration that they're using
– TheIncorrigible1
Nov 21 at 20:23
Cheers @TheIncorrigible1, your protips are always good!
– trebleCode
Nov 21 at 20:26
@trebleCode glad to be of service. You can also utilize that type's static memberAdd
to define your own type accelerators (I use this functionality in my$profile
for shortcuts)
– TheIncorrigible1
Nov 21 at 20:30
@TheIncorrigible1 good to know, I can forsee making alot of use of that in the near future
– trebleCode
Nov 21 at 20:36
|
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've written a code that tries to go through my company server and set all the excel files, under a certain folder, to shared so that multiple people can edit them at once. This has been a problem for a very long time here and I thought I had a nice code to fix this but I can't seem to access the property correctly. Can anyone help?
$ErrorActionPreference = "Stop"
$root = "P:A N G"
$excelFiles = Get-ChildItem -path $root -File "*.xlsx" -Recurse
foreach ($excelFile in $excelFiles.FullName)
{
$excel = New-Object -ComObject Excel.Application
$excelWorkBook = $excel.Workbooks.Open($excelFile)
if (!$excelWorkBook.MultiUserEditing)
{
Write-Host $excelFile
$excelWorkBook._SaveAs([Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlShared)
$excelWorkBook.Close
}
}
excel powershell
I've written a code that tries to go through my company server and set all the excel files, under a certain folder, to shared so that multiple people can edit them at once. This has been a problem for a very long time here and I thought I had a nice code to fix this but I can't seem to access the property correctly. Can anyone help?
$ErrorActionPreference = "Stop"
$root = "P:A N G"
$excelFiles = Get-ChildItem -path $root -File "*.xlsx" -Recurse
foreach ($excelFile in $excelFiles.FullName)
{
$excel = New-Object -ComObject Excel.Application
$excelWorkBook = $excel.Workbooks.Open($excelFile)
if (!$excelWorkBook.MultiUserEditing)
{
Write-Host $excelFile
$excelWorkBook._SaveAs([Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlShared)
$excelWorkBook.Close
}
}
excel powershell
excel powershell
asked Nov 21 at 19:54
user10484977
12
12
Is that accelerated .NET method,xlShared
, just a boolean? Also, after you callClose()
, most PS/Excel code I've seen calls.Quit()
after that as well. Are you able to open those Excel files from your machine? Or can you query the property on one of those Excel objects that you're trying to change after the code runs?
– trebleCode
Nov 21 at 20:06
@trebleCode For future reference, type accelerators are a specific class in the powershell library which essentially aliases types and the term does not apply to every use of a .NET type (which is what is happening here). Observe here:[psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get
It's likely an enumeration that they're using
– TheIncorrigible1
Nov 21 at 20:23
Cheers @TheIncorrigible1, your protips are always good!
– trebleCode
Nov 21 at 20:26
@trebleCode glad to be of service. You can also utilize that type's static memberAdd
to define your own type accelerators (I use this functionality in my$profile
for shortcuts)
– TheIncorrigible1
Nov 21 at 20:30
@TheIncorrigible1 good to know, I can forsee making alot of use of that in the near future
– trebleCode
Nov 21 at 20:36
|
show 3 more comments
Is that accelerated .NET method,xlShared
, just a boolean? Also, after you callClose()
, most PS/Excel code I've seen calls.Quit()
after that as well. Are you able to open those Excel files from your machine? Or can you query the property on one of those Excel objects that you're trying to change after the code runs?
– trebleCode
Nov 21 at 20:06
@trebleCode For future reference, type accelerators are a specific class in the powershell library which essentially aliases types and the term does not apply to every use of a .NET type (which is what is happening here). Observe here:[psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get
It's likely an enumeration that they're using
– TheIncorrigible1
Nov 21 at 20:23
Cheers @TheIncorrigible1, your protips are always good!
– trebleCode
Nov 21 at 20:26
@trebleCode glad to be of service. You can also utilize that type's static memberAdd
to define your own type accelerators (I use this functionality in my$profile
for shortcuts)
– TheIncorrigible1
Nov 21 at 20:30
@TheIncorrigible1 good to know, I can forsee making alot of use of that in the near future
– trebleCode
Nov 21 at 20:36
Is that accelerated .NET method,
xlShared
, just a boolean? Also, after you call Close()
, most PS/Excel code I've seen calls .Quit()
after that as well. Are you able to open those Excel files from your machine? Or can you query the property on one of those Excel objects that you're trying to change after the code runs?– trebleCode
Nov 21 at 20:06
Is that accelerated .NET method,
xlShared
, just a boolean? Also, after you call Close()
, most PS/Excel code I've seen calls .Quit()
after that as well. Are you able to open those Excel files from your machine? Or can you query the property on one of those Excel objects that you're trying to change after the code runs?– trebleCode
Nov 21 at 20:06
@trebleCode For future reference, type accelerators are a specific class in the powershell library which essentially aliases types and the term does not apply to every use of a .NET type (which is what is happening here). Observe here:
[psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get
It's likely an enumeration that they're using– TheIncorrigible1
Nov 21 at 20:23
@trebleCode For future reference, type accelerators are a specific class in the powershell library which essentially aliases types and the term does not apply to every use of a .NET type (which is what is happening here). Observe here:
[psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get
It's likely an enumeration that they're using– TheIncorrigible1
Nov 21 at 20:23
Cheers @TheIncorrigible1, your protips are always good!
– trebleCode
Nov 21 at 20:26
Cheers @TheIncorrigible1, your protips are always good!
– trebleCode
Nov 21 at 20:26
@trebleCode glad to be of service. You can also utilize that type's static member
Add
to define your own type accelerators (I use this functionality in my $profile
for shortcuts)– TheIncorrigible1
Nov 21 at 20:30
@trebleCode glad to be of service. You can also utilize that type's static member
Add
to define your own type accelerators (I use this functionality in my $profile
for shortcuts)– TheIncorrigible1
Nov 21 at 20:30
@TheIncorrigible1 good to know, I can forsee making alot of use of that in the near future
– trebleCode
Nov 21 at 20:36
@TheIncorrigible1 good to know, I can forsee making alot of use of that in the near future
– trebleCode
Nov 21 at 20:36
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
With some help from a friend I managed to come up with a solution actually.
$ErrorActionPreference = "Stop"
$root = "P:A N G"
$excelFiles = Get-ChildItem -path $root -File "*.xlsx" -Recurse
foreach ($excelFile in $excelFiles.FullName)
{
$excel = New-Object -ComObject Excel.Application
$excelWorkBook = $excel.Workbooks.Open($excelFile)
if (!$excelWorkBook.MultiUserEditing)
{
Write-Host $excelWorkBook.FullName
$accessMode = [Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlShared
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
$excelWorkBook.SaveAs($excelWorkBook.FullName,$xlFixedFormat,$null,$null,$null,$null,$accessMode,$null,$null,$null,$null,$null)
$excelWorkBook.Close
}
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
With some help from a friend I managed to come up with a solution actually.
$ErrorActionPreference = "Stop"
$root = "P:A N G"
$excelFiles = Get-ChildItem -path $root -File "*.xlsx" -Recurse
foreach ($excelFile in $excelFiles.FullName)
{
$excel = New-Object -ComObject Excel.Application
$excelWorkBook = $excel.Workbooks.Open($excelFile)
if (!$excelWorkBook.MultiUserEditing)
{
Write-Host $excelWorkBook.FullName
$accessMode = [Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlShared
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
$excelWorkBook.SaveAs($excelWorkBook.FullName,$xlFixedFormat,$null,$null,$null,$null,$accessMode,$null,$null,$null,$null,$null)
$excelWorkBook.Close
}
}
add a comment |
up vote
0
down vote
With some help from a friend I managed to come up with a solution actually.
$ErrorActionPreference = "Stop"
$root = "P:A N G"
$excelFiles = Get-ChildItem -path $root -File "*.xlsx" -Recurse
foreach ($excelFile in $excelFiles.FullName)
{
$excel = New-Object -ComObject Excel.Application
$excelWorkBook = $excel.Workbooks.Open($excelFile)
if (!$excelWorkBook.MultiUserEditing)
{
Write-Host $excelWorkBook.FullName
$accessMode = [Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlShared
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
$excelWorkBook.SaveAs($excelWorkBook.FullName,$xlFixedFormat,$null,$null,$null,$null,$accessMode,$null,$null,$null,$null,$null)
$excelWorkBook.Close
}
}
add a comment |
up vote
0
down vote
up vote
0
down vote
With some help from a friend I managed to come up with a solution actually.
$ErrorActionPreference = "Stop"
$root = "P:A N G"
$excelFiles = Get-ChildItem -path $root -File "*.xlsx" -Recurse
foreach ($excelFile in $excelFiles.FullName)
{
$excel = New-Object -ComObject Excel.Application
$excelWorkBook = $excel.Workbooks.Open($excelFile)
if (!$excelWorkBook.MultiUserEditing)
{
Write-Host $excelWorkBook.FullName
$accessMode = [Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlShared
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
$excelWorkBook.SaveAs($excelWorkBook.FullName,$xlFixedFormat,$null,$null,$null,$null,$accessMode,$null,$null,$null,$null,$null)
$excelWorkBook.Close
}
}
With some help from a friend I managed to come up with a solution actually.
$ErrorActionPreference = "Stop"
$root = "P:A N G"
$excelFiles = Get-ChildItem -path $root -File "*.xlsx" -Recurse
foreach ($excelFile in $excelFiles.FullName)
{
$excel = New-Object -ComObject Excel.Application
$excelWorkBook = $excel.Workbooks.Open($excelFile)
if (!$excelWorkBook.MultiUserEditing)
{
Write-Host $excelWorkBook.FullName
$accessMode = [Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlShared
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
$excelWorkBook.SaveAs($excelWorkBook.FullName,$xlFixedFormat,$null,$null,$null,$null,$accessMode,$null,$null,$null,$null,$null)
$excelWorkBook.Close
}
}
answered Nov 21 at 20:49
user10484977
12
12
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419596%2fpowershell-script-for-setting-multi-user-editing-in-excel-for-numerous-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is that accelerated .NET method,
xlShared
, just a boolean? Also, after you callClose()
, most PS/Excel code I've seen calls.Quit()
after that as well. Are you able to open those Excel files from your machine? Or can you query the property on one of those Excel objects that you're trying to change after the code runs?– trebleCode
Nov 21 at 20:06
@trebleCode For future reference, type accelerators are a specific class in the powershell library which essentially aliases types and the term does not apply to every use of a .NET type (which is what is happening here). Observe here:
[psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get
It's likely an enumeration that they're using– TheIncorrigible1
Nov 21 at 20:23
Cheers @TheIncorrigible1, your protips are always good!
– trebleCode
Nov 21 at 20:26
@trebleCode glad to be of service. You can also utilize that type's static member
Add
to define your own type accelerators (I use this functionality in my$profile
for shortcuts)– TheIncorrigible1
Nov 21 at 20:30
@TheIncorrigible1 good to know, I can forsee making alot of use of that in the near future
– trebleCode
Nov 21 at 20:36