Current folder

  • Thread starter Thread starter Khalil Handal
  • Start date Start date
K

Khalil Handal

I have VBA code for inserting a picture as a header with the following code:

With ActiveSheet.PageSetup
.CenterHeader = "&G"
.CenterHeaderPicture.Filename =
"D:\Rosary\School_System\ROS_Logo.tif"

What changes should be done in order to use the current folder in which the
files are stored in? (If I moved the folder to another drive this will ot
work).
I tried the following in different ways, but no success!

..CenterHeaderPicture.Filename = ("ThisWorkbook.Path & "\ROS_logo.tif")
 
If the activesheet isn't a sheet in the workbook that contains the code, then
that code will fail.

Maybe you can use:

.CenterHeaderPicture.Filename = activesheet.parent.Path & "\ROS_logo.tif"
 
And since you're using:

With Activesheet.pagesetup
'...
.CenterHeaderPicture.Filename = .parent.parent.Path & "\ROS_logo.tif"
end with

It might be more useful if you ever change from using Activesheet.
 
I tried both and have the error code:
Run time error 1004
Application defined or object define error

Note: The code is in a sheet named "Marks" : I have a button to press to run
the code
See the full code please:
Sub printcert()
Dim cell As Variant

For Each cell In Range("certprint")
If cell.Value = 1 Then
Sheets("Cer_2_M").Range("a3").Value = cell.Offset(0, -90)
Sheets("Cer_2_M").Select
' (ThisWorkbook.Path & "\logo_r.tif")
With ActiveSheet.PageSetup
.CenterHeader = "&G"
'.CenterHeaderPicture.Filename =
"D:\Rosary\School_System\ROS_Logo.tif"
'.CenterHeaderPicture.Filename = .Parent.Parent.Path &
"\ROS_logo.tif"
.CenterHeaderPicture.Filename = ActiveSheet.Parent.Path &
"\ROS_logo.tif"
.LeftHeader = "&""Arial,Bold""&11Rosary Sisters" & Chr(10) &
"&""Times New Roman,Bold""&11 Paul VI St."
.RightHeader = "&""PT Bold Heading""&12ãÏÑÓÉ ÑÇåÈÇÊ ÇáæÑÏíÉ" &
Chr(10) & "&""Traditional Arabic,Bold""&14 Ô. ÈæáÓ ÇáÓÇÏÓ"
.LeftFooter = "&""small fonts,Regular""&5Designed by Khalil Handal"
End With
' ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWindow.SelectedSheets.PrintPreview
End If
Next

End Sub
 
It looks to me that the code belongs in a General module--not behind the sheet
named Marks (or any sheet).

And it looks like the .centerheaderpicture lines are commented out. So I don't
see how they could be causing the error.

What line causes the error?

Khalil said:
I tried both and have the error code:
Run time error 1004
Application defined or object define error

Note: The code is in a sheet named "Marks" : I have a button to press to run
the code
See the full code please:
Sub printcert()
Dim cell As Variant

For Each cell In Range("certprint")
If cell.Value = 1 Then
Sheets("Cer_2_M").Range("a3").Value = cell.Offset(0, -90)
Sheets("Cer_2_M").Select
' (ThisWorkbook.Path & "\logo_r.tif")
With ActiveSheet.PageSetup
.CenterHeader = "&G"
'.CenterHeaderPicture.Filename =
"D:\Rosary\School_System\ROS_Logo.tif"
'.CenterHeaderPicture.Filename = .Parent.Parent.Path &
"\ROS_logo.tif"
.CenterHeaderPicture.Filename = ActiveSheet.Parent.Path &
"\ROS_logo.tif"
.LeftHeader = "&""Arial,Bold""&11Rosary Sisters" & Chr(10) &
"&""Times New Roman,Bold""&11 Paul VI St."
.RightHeader = "&""PT Bold Heading""&12ãÏÑÓÉ ÑÇåÈÇÊ ÇáæÑÏíÉ" &
Chr(10) & "&""Traditional Arabic,Bold""&14 Ô. ÈæáÓ ÇáÓÇÏÓ"
.LeftFooter = "&""small fonts,Regular""&5Designed by Khalil Handal"
End With
' ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWindow.SelectedSheets.PrintPreview
End If
Next

End Sub
 
Yes, the code belongs to a general module. What effect this will cause?The
button to click is in the sheet named "Marks"
I tried the following 2 lines of code one at a time and had the error:

..CenterHeaderPicture.Filename = .Parent.Parent.Path & "\ROS_logo.tif"
..CenterHeaderPicture.Filename = ActiveSheet.Parent.Path & "\ROS_logo.tif"
 
I'd check that folder and see if there really is a file by that name. I'm
guessing that you mistyped its name.

Khalil said:
Yes, the code belongs to a general module. What effect this will cause?The
button to click is in the sheet named "Marks"
I tried the following 2 lines of code one at a time and had the error:

.CenterHeaderPicture.Filename = .Parent.Parent.Path & "\ROS_logo.tif"
.CenterHeaderPicture.Filename = ActiveSheet.Parent.Path & "\ROS_logo.tif"
 
Back
Top